您的位置:首页 > 编程语言 > Python开发

python写的掉空格数字字母的方法

2014-02-15 17:02 501 查看
def tripNumsAlpha():
'''patt=re.compile(r"[^0-9]") then we would get like str1=''.join(re.findall(patt,"1215北京"))
str1=>'北京'.Now you see what you want to .
'''
import re

patt=re.compile(r"[^0-9a-zA-Z]")
lis1=[]

with open('D:\\clrename\\clearspace.txt', 'r') as f:
for it in f.readlines():
str1=''.join(re.findall(patt,it))
lis1.append(str.lstrip(str1))

f.close()

with open('D:\\clrename\\clearspace-out.txt', 'w+') as f1:
for it in lis1:
print(it)
f1.writelines(it)
f1.close()
print("-"*4+"Finished"+"-"*4)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: