Python command line 'file input stream'

前端 未结 3 1415
小蘑菇
小蘑菇 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条回答
  •  -上瘾入骨i
    2021-01-12 00:03

    Using the fileinput module would be most appropriate here, and more flexible.

    http://docs.python.org/library/fileinput.html

    import fileinput
    for line in fileinput.input():
        process(line)
    

    In addition to supporting stdin, it can also read from files listed as arguments.

提交回复
热议问题