我对 Python 很陌生。目前我正在尝试编写一个脚本,该脚本可以读取.txt
包含一堆数据的文件,并提取格式为(xxx)xxx-xxxx
.
这是我目前的尝试,但它根本不起作用,我迷路了:
#import argv
from sys import argv
script, filename = argv
txt_file = open(filename)
indata = txt_file.read()
#confirm to the user what file is being open
print "Opening %r" % filename
#create a loop to read through the file
for line, in line enumerate(indata):
if line == "(" + \w\w\w\ + ")" + \w\w\w "-" + \w\w\w
print line
txt_file.close()
任何人都可以向我提供有关如何进行这项工作的建议吗?