我正在写一个python代码来从.txt文件中提取所有信息。我已经写代码,但来到永诺错误:“NoneType”对象有没有属性“groupdict”python re groupdict
代码:
import re
readfile = open("test.txt")
try:
all_the_text =readfile.read()
m = re.match("(pdflink=[\w\s/]*)author=([\w\s/]*/n)",unicode(all_the_text),flags=re.UNICODE)
m.groupdict()
print m.groupdict()
finally:
readfile.close()
writefile = open('test5.txt','w')
print >> writefile, m.groupdict()
writefile.close()
请帮帮我吧!谢谢!
这意味着你的're.match'永远不会匹配任何东西......你确定你不应该使用're.search'吗? [它可能有助于显示一些示例输入数据...] –
匹配方法,如果字符串与模式不匹配,则返回None类型,如 – felipsmartins