Skip to content

Instantly share code, notes, and snippets.

@bonprosoft
Last active August 28, 2018 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bonprosoft/d7a365f6e024233bfbaac683e11cd033 to your computer and use it in GitHub Desktop.
Save bonprosoft/d7a365f6e024233bfbaac683e11cd033 to your computer and use it in GitHub Desktop.
sys.stdinの挙動の違い
import sys
for x in sys.stdin:
sys.stdout.write('stdin: {}'.format(x))
sys.stdout.flush()
"""Output.
[py36]
hoge
stdin: hoge
fuga
stdin: fuga
^D
[py27]
hoge
stdin: hoge
fuga
stdin: fuga
^D
"""
import sys
for x in sys.stdin:
sys.stdout.write('stdin: {}'.format(x))
sys.stdout.flush()
"""Output.
[py36]
hoge
stdin: hoge
fuga
stdin: fuga
^D
[py27]
hoge
fuga
^D
stdin: hoge
stdin: fuga
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment