我寫了下面的腳本以匿名電子郵件地址的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