Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
コマンドラインで入力として指定したファイルを .py ファイルに受け入れさせたい。sys.argv[] と fileinput も使用しましたが、出力が得られません。
次のスクリプトを作成する場合:
#!/usr/bin/env python import sys with open(sys.argv[1], 'r') as my_file: print(my_file.read())
それを実行すると、次のように最初の引数に渡した名前のファイルの内容が表示されます。
./my_script.py test.txt
(上記の例では、このファイルは になりますtest.txt)。
test.txt