How to read user input until EOF in python?

前端 未结 5 1462
囚心锁ツ
囚心锁ツ 2020-12-14 12:19

I came across this problem in UVa OJ. 272-Text Quotes

Well, the problem is quite trivial. But the thing is I am not able to read the input. The input is provided in

5条回答
  •  盖世英雄少女心
    2020-12-14 13:02

    You can use sys module:

    import sys
    
    complete_input = sys.stdin.read()
    

    sys.stdin is a file like object that you can treat like a Python File object.

    From the documentation:

    Help on built-in function read:

    read(size=-1, /) method of _io.TextIOWrapper instance Read at most n characters from stream.

    Read from underlying buffer until we have n characters or we hit EOF.
    If n is negative or omitted, read until EOF.
    

提交回复
热议问题