ファイル名が空白のファイルがあるディレクトリがあります。これらのファイルを読み込んで、tail -n1
コマンドを実行するPythonスクリプトがありますが、名前に空白があるためそれは失敗します。たとえば。ディレクトリに空白を含むファイル名を扱う
私は、次のファイル
data from_10_13_2014 09_00_45.json
とdirctoryを持っていると私は次のエラー
tail: cannot open ‘/home/dataserver/Development/Test/data’ for reading: No such file or directory
tail: cannot open ‘from_10_13_2014’ for reading: No such file or directory
tail: cannot open ‘09_00_45.json’ for reading: No such file or directory
に回避策を取得し、今のように私のスクリプトは次の行line = os.popen("tail -n1 %s" % files).read()
が含まれています私は現在、空白を_
に置き換えていますファイルは?
は、残念ながら私は、そのファイル名を制御することはできません彼らは我々が使用するセンサーによって生成され、それを変更する方法はありません、ありがとうございます。 – cyberbemon
ああ、人生は時々難しいです:) –