1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Pythonで複数入力(無限入力)を実行する方法

Last updated at Posted at 2022-02-23
test.py
import sys

lines = []
for l in sys.stdin:
    lines.append(l.rstrip('\r\n'))

上記のようなコードでは、

python test.py

のように実行しても無限に入力を受け付けてしまい、最後まで実行できませんでした。
(追記)Linux・Macの場合はCtrl+D、Windows なら Ctrl+Zでできました。コメントありがとうございます。

下記でも実行できます。

echo "test1.txt" "text2.txt" | python test.py

参考:https://stackoverflow.com/questions/43554363/how-to-run-code-with-sys-stdin-as-input-on-multiple-text-files

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?