LoginSignup
5
4

More than 5 years have passed since last update.

【Python】input()からsys.stdin.readline().strip()への変更

Posted at

やりたいこと

競プロで処理時間が長すぎた時に,処理部分のコードは変えずにinput()sys.stdin.readline().strip()に変更する。

入力

input.txt
10
hoge
foo foo

うまくいった方法

def input(): return sys.stdin.readline().strip()
[print(input()) for _ in range(3)]
'''出力
10
hoge
foo foo
'''

うまく行かなかった方法

理由は分かりませんが一行目しか取れませんでした。ご存知の方いたら教えてくださいm(_ _)m

input = sys.stdin.readline().strip
[print(input()) for _ in range(3)]
'''出力
10
10
10
'''
5
4
4

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
5
4