标签:
1、编辑工具:PyCharm4.5.1
http://www.jetbrains.com/pycharm/download/ 下载左侧的完全版
2、安装好python3.3.5后
http://rj.baidu.com/soft/detail/17016.html
3、读取chengyu.txt,按行处理后,保存到test111.txt中。文本文件都是utf-8的
# -*- coding: utf-8 -*- html = "" fo = open(‘d:/chengyu.txt‘, ‘a+‘) #以读写方式处理文件IO fo.seek(0) str_line = fo.readline() while str_line: # print(str_line) str_line = fo.readline() # 有两种标签<h3> 和 <p>,处理<p>标签中所含的成语 # str_line = "<p>急中生智 仰不愧天 镇定自若 化险为夷</p>" str_line2 = "" is_word = str_line.find("<p>") if is_word>-1: print("----是成语所在行----") # print(str_line) str_line = str_line.replace("<p>","") str_line = str_line.replace("</p>","") str_line = str_line.replace("\n","") for _word in str_line: if _word.find(" ")>-1: str_line2 = str_line2 + "</u>" + _word + "<u>" elif _word.find("、")>-1: str_line2 = str_line2 + "</u>" + _word + "<u>" else: str_line2 = str_line2 + _word str_line2 = "<u>" + str_line2 + "</u>" html = html + "<p>" + str_line2 + "</p>\n" else: print("----NO-所在行----") html = html + str_line # print(str_line) fo.close fo2 = open(‘d:/test111.txt‘,"w") fo2.write(html) fo2.close()
标签:
原文地址:http://www.cnblogs.com/qq21270/p/4591318.html