from __future__ import with_statement
import re
data_re = re.compile(ur'^:(\w+)\s+\("(.+?)"\)$')
data = []
with open('xxx.txt') as f:
for line in f:
if line.startswith(':'):
found = data_re.findall(line.strip())
if found:
data.append(found[0])
print data
请问,你用的是python3x 还是python2x啊?因为python3与python2对字符串有一些改变。
你的txt文本中有除了ascii之外的字符吗?
python中#本来就是行注释