我编写了一个程序,该程序一次读取多个文件的最后一行,并将输出打印为元组列表。
from os import listdir
from os.path import isfile, join
import subprocess
path = "/home/abc/xyz/200/coord_b/"
filename_last_lines = [[(filename, subprocess.check_output(['tail', '-1', path +
filename]))] for filename in [f for f in listdir(path) if isfile(join(path, f)) and
f.endswith('.txt')]]
print(filename_last_lines)
我现在得到的输出是(coord_70.txt,P),(coord_4.txt,R)等等,这是非常随机的。我需要按数字顺序打印它,如(coord_1.txt,R),(coord_2.txt,R)等。你能建议我修改这个代码吗?
互换的青春
一只名叫tom的猫
偶然的你
慕容708150
随时随地看视频慕课网APP
相关分类