心理学研究室で使用している実験実行ソフトウェアからのデータ ファイルを解析するための単純なコマンド ライン/ターミナル Python プログラムをいくつか作成しました。これらのプログラムは、一般的にコンピュータに精通している人々によって使用されますが、フラグを使用した本格的な UNIX スタイルのコマンドに対応している必要はありません。そのため、通常、プログラムに「どのファイルを処理しますか? " 次のように、ユーザーにリストから選択してもらいます。
import textwrap
import os
import sys
def get_folder():
""" Print a numbered
list of the subfolders in the working directory
(i.e. the directory the
script is run from),
and returns the directory
the user chooses.
"""
print(textwrap.dedent(
"""
Which folder are your files located in?
If you cannot see it in this list, you need
to copy the folder containing them to the
same folder as this script.
"""
)
)
dirs = [d for d in os.listdir() if os.path.isdir(d)] + ['EXIT']
dir_dict = {ind: value for ind, value in enumerate(dirs)}
for key in dir_dict:
print('(' + str(key) + ') ' + dir_dict[key])
print()
resp = int(input())
if dir_dict[resp] == 'EXIT':
sys.exit()
else:
return dir_dict[resp]
これらの種類のファイル チューザーの実装が Python ライブラリに出回っていますか? 私は通常、必要なときにいつでも自分ですばやく実装していますが、コードをファイルからファイルにコピーして貼り付け、それらを使用している特定のケースに合わせて変更する必要があります。