Python read from command line arguments or stdin

China☆狼群 提交于 2019-12-05 02:37:37
eumiro

You need fileinput.

A standard use case is:

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

In Python 3, argparse handles filetype objects very nicely. It's an extremely powerful module and the docs come with many examples, so it's easy to quickly write the code you want. (How Pythonic!)

You may also benefit from this StackOverflow question about using argparse to optionally read from stdin.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!