Python command line 'file input stream'

前端 未结 3 1414
小蘑菇
小蘑菇 2021-01-11 23:19

I\'m fairly new to python coming from C/C++, I was wondering how I would get my \'main.py\' to reconize/use the imput given from a bash shell as:

pyth

3条回答
  •  走了就别回头了
    2021-01-12 00:11

    Read from sys.stdin:

    import sys
    sys.stdin.read()
    

    Being a file-like object, you can use its reading functions or simply iterate over the input lines:

    for line in sys.stdin:
        print line
    

提交回复
热议问题