Command line arguments in Windows

Chris cwitts at gmail.com
Tue Mar 4 01:01:31 EST 2008


On Mar 4, 7:12 am, "Mike Walker" <mhwal... at shaw.ca> wrote:
> I am having some problems with command line arguments in Windows. The same
> code under Linux works fine.
>
> In Windows I only get one argument no matter how many arguments are passed
> on the command line. I think there is some problem with the way the .py
> files are associated causing this. I'm just not sure how to go about fixing
> it.
>
> If I call the python script using the command "python argtest.py arg1 arg2
> etc..." this also works fine. Its only when run the program using the name
> only that the problem occurs.
>
> Does anyone have any ideas what the problem is here and hopefully how to go
> about fixing it?
>
> import sys
>
> if __name__ == "__main__":
>     for arg in sys.argv:
>         print arg

If you run a python file, ie. just double clicking it the only
argument you will have will be the filename of the script.  If you
create a shortcut to the script and in the target box add your
arguments (if you have quotation marks place them after not inside)
you will see your arguments.  fwiw you answered yourself in the third
paragraph.



More information about the Python-list mailing list