python正则表达式处理txt_使用python的读取文件内容和正则表达式

import os,re

filePath='cadallkeywords.txt'

fileOutPath='out.txt'

strOut=[]

if os.path.exists(filePath):

with open(filePath,'r', encoding='utf-8') as fin:

keywords=fin.readlines()

fin.close()

with open(fileOutPath,'w',encoding='utf-8') as fout:

for line in keywords:

pattern=re.compile(r'[a-zA-z]+')

result=pattern.findall(line)

for word in result:

fout.write(word.lower()+'\n')

# fout.writelines(result)

print('done')

fout.close()

# keywords='Activate AppActivate AppDeactivate ARXLoaded ARXUxtloaded BeginClose BeginCommand BeginDocClose BeginDoubleCli ck BeginFileDrop BeginLISP BegirJflodal BeginOpen BeginPlot BeginQui t BeginRightClick BeginSave \

# B e gi iiShor t cutM enuC omm and B e gi iiShor t cutM enuD e £aul t BegiiiShortcutMenuEdi t B e gi iiShor t cutM enuGr i p B e gi iiShor t cutM enuOSnap Deactivate EndCommand EndIJSP EndJilodal EndOpen EndPlot EndSave \

# EndShor t cutM enu LayoutSwitched USPCancelled Modified\n'

你可能感兴趣的:(python正则表达式处理txt_使用python的读取文件内容和正则表达式)