Help - command line arguments

Emile van Sebille emile at
Sun Dec 30 00:42:05 EST 2001

"Steve Zatz" <slzatz at> wrote in message
news:YpxX7.242028$bs2.45285312 at
> I am new to Python and although I am sure that the following is obvious I
> can't figure the following out or find an answer in any of the texts that
> have access to.
> My question is:  Can you run a script that takes command line arguments
> within the Python shell or from the Python command line?
> For example, something like:
> -a -b
> runs fine from the *Windows XP* command prompt.
> From the Python command line, I can do the following:
> import test
> test.main()
> which doesn't produce an exception but I can't figure out how to input the
> command line arguments.
> And from the Python Shell, just running test.main() produces a getopt
> exception which does not occur when it runs from the Python command line.
> (But in either case, I can't figure out how to use command line
> Again, any help would be appreciated.  Thanks.

import sys
print sys.argv

C:\>python -c "import os; print os.popen(' passed_arg').read()"
['C:\\', 'passed_arg']

Or you could force sys.argv appropriately:

import test
import sys
sys.argv = [test.__file__, 'my_argv1', 'etc...']



Emile van Sebille
emile at


More information about the Python-list mailing list