我有一系列文件,我想从每个文件中提取一个特定的数字。在每个文件中,我都有这一行:
name, registration num
紧随其后的两行是注册号。我想从每个文件中提取这个数字。并将其作为字典的值。有人知道这怎么可能吗?
我当前实际上不起作用的代码如下:
matches=[]
for root, dirnames, filenames in os.walk('D:/Dataset2'):
for filename in fnmatch.filter(filenames, '*.txt'):
matches.append([root, filename])
filenames_list={}
for root,filename in matches:
filename_key = (os.path.join(filename).strip()).split('.',1)[0]
fullfilename = os.path.join(root, filename)
f= open(fullfilename, 'r')
for line in f:
if "<name, registration num'" in line:
key=filename_key
line+=2
val=line