def stripFile(oldFile, newFile): '''remove the space or Tab or enter in a file, and output a new file in the same folder''' f = open(oldFile, 'r+', encoding='utf8') newf = open(newFile, 'w',encoding='utf8') for eachline in f.readlines(): newStr = eac
import re import os input_path = 'G:/test/aa.json' output_path ='G:/test/bb.json' with open(input_path) as input_file: str = input_file.read() str = re.sub('\s','',str) print str with open(output_path, 'w') as output_file: output_file.write(str)
将文本中的 tasting123删除 with open("fileread.txt","r",encoding="utf-8") as f: lines = f.readlines() #print(lines) with open("fileread.txt","w",encoding="utf-8") as f_w: for line in lines: if "tast
def SplitHtmlTag(file): with open(file,"r") as f,open("result.txt","w+") as c: lines=f.readlines() for line in lines: re_html=re.compile(r'<[^>]+>')#从'<'开始匹配,不是'>'的字符都跳过,直到'>' line=re_html.sub('',line) c.wri
pandas 操作csv文件时,一直报错,排查后发现csv文本中存在很多“空行”: So 需要把空行全部去掉: def clearBlankLine(): file1 = open('text1.txt', 'r', encoding='utf-8') # 要去掉空行的文件 file2 = open('text2.txt', 'w', encoding='utf-8') # 生成没有空行的文件 try: for line in file1.readlines(): if line == '\n'