Sunday, May 24, 2009

Avoid the *.py extension when calling scripts under Windows

If you'd like to make your scripts run by typing

myscript args

instead of args

you can wrap the python script inside a *.bat file. Say you want to run and it takes two arguments, make the following batch DOS file: %1 %2

The percentage+number things play the role of sys.argv in Python such that command line arguemnts are piped through to the Python script.


  1. Add .py to your PATHEXT environment variable and you can run Python files at the command line without the extension. No need to wrap in a batch file.

  2. Ah... good point. (I come from the other camp... just playing with Windows now and then. Thanks!)