accidental_coder:
私は一度に複数のファイルの最後の行を読み取り、タプルのリストとして出力しますプログラムを書かれています。
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)などのように番号順にこれを印刷する必要があります。あなたは私がこのコードに変更する提案してくださいことはできますか?
scenox:
ただ、LISTDIRに()ソート適用されます。
filename_last_lines = [[(filename, subprocess.check_output(['tail', '-1', path +
filename]))] for filename in [f for f in sorted(listdir(path)) if isfile(join(path, f)) and
f.endswith('.txt')]]