piping into a python script
hexamorph at gmx.net
Thu Jan 24 18:53:22 CET 2008
Donn Ingle wrote:
> Paddy wrote:
>> fileinput is set to process each file a line at a time unfortunately.
> Wow. So there seems to be no solution to my OP. I'm amazed, I would have
> thought a simple list of strings, one from stdin and one from the args,
> would be easy to get.
> I *really* don't want to open each file, that would be insane.
> Perhaps I shall have to forgo the stdin stuff then, after all.
I'm not sure if I completely get what you want, but what's about this:
filelist = 
if len(sys.argv) > 1:
for file in sys.argv[1:]:
if file == "-":
for file in sys.stdin:
for file in filelist:
print "Processing file: %s" % file
It's a bit clumsy, but seems to do what I guess you want.
More information about the Python-list