fileinputモジュールを使います。
import fileinput
for line in fileinput.input():
print(line,end="")
以下のどの呼び出し方でも、使えます。ファイルの中身を表示するだけの例なので、あまり面白くはないですが(^^;
python3 test.py test.py
python3 test.py < test.py
cat test.py | python3 test.py
More than 5 years have passed since last update.
fileinputモジュールを使います。
import fileinput
for line in fileinput.input():
print(line,end="")
以下のどの呼び出し方でも、使えます。ファイルの中身を表示するだけの例なので、あまり面白くはないですが(^^;
python3 test.py test.py
python3 test.py < test.py
cat test.py | python3 test.py
Register as a new user and use Qiita more conveniently