ディレクトリに多数のログファイルがあり、それらの範囲のみが必要な場合、別のオプションは、範囲とベースを取り、それぞれのログをインポートするだけの小さな Python スクリプトを作成することです (または、特に凝りたい場合は、実際にimport_logs
直接インポートできます)。
Popen
Python では、任意のシェル コマンドを実行できます。したがって、 を実行したい場合はimport_logs log_base_str01123.txt
、次のように実行できます。
from subprocess import Popen, PIPE
print Popen("import_logs.py log_base_str01123.txt", stdout=PIPE, shell=True).stdout.read()
そして、一連の文字列に対してそれを行いたい場合:
from subprocess import Popen, PIPE
import os
base_prefix = "u_ex"
base_suffix = ".log"
logs=["my", "list", "of", "log#s"]
for log in logs:
path = "import_logs.py {prefix}{log_name}{suffix}".format(
prefix=prefix, log_name=log, suffix=base_suffix)
if not os.path.exists(log):
print Popen(,
stdout=PIPE, shell=True).stdout.read())
これは、より汎用的なソリューションになる可能性があり、よりきめ細かい制御が可能になります。
連続した値のリストを調べたい場合は、次を使用できます。
logs = map(str, range(start_number, end_number + 1))