我试图从 10 个不同的文本文件中仅从特定行中获取数字。作为输出,我希望将这些数字附加为列表。我是一个新的学习者。我会很感激你的帮助。试过这个但不工作
import os
import sys,re
line_number=69
path = r'C:\Users\arpan\OneDrive\Desktop\New folder'
for filename in os.listdir(path):
with open(os.path.join(path, filename), 'r') as f:
#print (filename)
file = open(filename)
all_lines_variable = file.readlines()
sys.stdout = open("output", "a") #print output file
print(filename, all_lines_variable[line_number])
sys.stdout.close()