KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
When writing text-oriented command line programs in Python, I often want to read either all the files passed on the command line, or (XOR) standard input (like Unix cat does, or Perl's <> ). So, I say if len(args) == 0: # result from optparse input = sys.stdin else: input = itertools.chain(*(open(a) for a in args)) Is this the Pythonic way of doing this, or did my miss some part of the library?
Tags (comma-separated)
Save Edits
Cancel