无标题文章

2016-05-30  本文已影响0人  jianjianxin2011

# _*_coding:UTF-8 _*_

importre

file="C:/Users/roxy.fu/Desktop/michelin_KOL.txt"

file=open(file,"+r",encoding="UTF-8")

str=file.read()

p=re.findall("(?x) ( [^\w] )",str)#(?x) ( [\w]+|[\x80-\xff]{3} 取中文英文数字

s='.'.join(p)#将列表转换成字符串

print(s)

通过readline输出,对于比较大的文件,这种占用内存比较小。

#coding:utf-8

f = open('poem.txt','r')

result = list()

forlineinopen('poem.txt'):

line = f.readline()

printline

result.append(line)

printresult

f.close()

open('result-readline.txt','w').write('%s'%'\n'.join(result))

#importre

file="C:/Users/roxy.fu/Desktop/michelin_KOL.txt"

result=list()

file=open(file,"+r",encoding="UTF-8")

lines=file.readlines()

forlineinlines:

p = re.findall("(?x)([\w]+|[\x80-\xff]{3})",line)# (?x) ( [\w]+|[\x80-\xff]{3} 取中文英文数字

result.append(p)

str='\n'.join([str(i)foriinresult]).replace('[',"").replace(",","").replace("]","")

open("C:/Users/roxy.fu/Desktop/result_michelin.txt",'w',encoding="UTF-8").write(str)

上一篇下一篇

猜你喜欢

热点阅读