我写了下面的脚本以匿名电子邮件地址的txt文件:如何在所有目录执行python脚本
import io, os, sys
import re
def main():
try:
# Open the file.
myfile = open('emails.txt', 'r')
# Read the file's contents.
content = myfile.read()
content = re.sub(r'.+([email protected]+\.(com|edu))', "xxxx", content)
myfile = open('emails.txt', 'w')
myfile.write(content)
# Close the file.
myfile.close()
except IOError:
print('An error occured trying to read the file.')
except:
print('An error occured.')
main()
我不知道我怎么会做这项工作的所有目录中的文件及其子目录。
退房这个问题:http://stackoverflow.com/questions/120656/directory-listing-in-python – 2013-03-05 07:57:05
你没有使用io,os或sys – joaquin 2013-03-05 07:58:35
是的,我意识到我并不需要那些 – user2063763 2013-03-05 07:59:08