nynw.net
当前位置:首页 >> python文本切分 >>

python文本切分

def writeStr(url,content):with open(url,'w') as f:f.write(content)longStr = "123 23 货物A 货物B 货物C 货物D 货物E 货物F 45 78 货物G 货物H 货物I 货物J 货物K 货物L"regObj = re.compile(r"[\d+\s+]+")saveurl = "E:/dataSave/" #把这个...

s = open(file,'r') q = s.read() f = q.split('\n\n') for i in f: print i s.close 用两个换行符来分

import retext=open(r'a.txt').read()matches=re.finditer(r'(\S+)\s(.*)',text)b=open('b.txt','w')c=open('c.txt','w')for match in matches: b.write(match.group(1)+'\n') c.write(match.group(2)+'\n')b.close()c.close()

标点有很多。。 (逗号,分好,句号,感叹号,问好) 都要分么。。 如果都要分,就用re模块的split 如果只按一种分,直接用split函数

with open('a.txt','r') as fa,open('b.txt','w') as fb,open('c.txt','w') as fc: for line in fa: for i in line.split(' '): if not '.' in i: fb.write(i+' ') else: fc.write(i+' ') fb.write('\n') fc.write('\n')

def splitfile(filename,sizelimit,forline=True): size=0 i=1 out=open("%s.%04d"%(filename,i),'w') for line in open(filename): size=size+1 if forline else size+len(line) if(size>sizelimit): size=1 if forline else len(line) out.clo...

把fv2=open('新文件'+'n','w')中的'n'改成str(n)

按行读取之后按原文件编码类型解码,插入完后按UTF-8解码写入文件 以源文件为gbk为例,假设每5字符插入| python2 with open('target','w') as f: for line open('source').readlines(): line=line.decode('gbk') line='|'.join([line[i:min(i+5,...

a = '1234' for b in a : print (b) 其实这样就可以了~但是功能比较单一

网站首页 | 网站地图
All rights reserved Powered by www.nynw.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com