Automatically open files given as command line arguments in Python

Posted by mk on Stack Overflow See other posts from Stack Overflow or by mk
Published on 2010-03-28T16:47:39Z Indexed on 2010/03/28 16:53 UTC
Read the original article Hit count: 281

I have a lot of Perl scripts that looks something like the following. What it does is that it will automatically open any file given as a command line argument and in this case print the content of that file. If no file is given it will instead read from standard input.

while ( <> ) {
    print $_;
}

Is there a way to do something similar in Python without having to explicitly open each file?

© Stack Overflow or respective owner

Related posts about python

Related posts about command-line-arguments