我正在寫一個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