日期是8位数字,在collection_date:之后,例如/collection_date:20120403
使用pycharm编写了程序:
import re
with open ('3215 HBV1.txt') as f:
for dates in f:
collection = re.findall(r'collection_date:(\d\d\d\d\d\d\d\d)',dates)
print(collection[0])
总是报错:
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/untitled2/TXTextract.py", line 7, in <module>
print(collection[0])
IndexError: list index out of range
请高人指教,程序应该如何调整,多谢