How do you read from stdin?

后端 未结 22 2595
余生分开走
余生分开走 2020-11-21 06:46

I\'m trying to do some of the code golf challenges, but they all require the input to be taken from stdin. How do I get that in Python?

22条回答
  •  我在风中等你
    2020-11-21 07:21

    This will echo standard input to standard output:

    import sys
    line = sys.stdin.readline()
    while line:
        print line,
        line = sys.stdin.readline()
    

提交回复
热议问题