[Tutor] Running python from windows command prompt

eryksun eryksun at gmail.com
Wed Apr 10 17:29:02 CEST 2013


On Wed, Apr 10, 2013 at 8:32 AM, Arijit Ukil <arijit.ukil at tcs.com> wrote:
>
> python my_python.py 1 3  2

Adding Python's installation directory to PATH is for starting the
interpreter with specific options (-O, -vv, etc), running a module on
Python's sys.path (-m), running a command (-c), or starting an
interactive shell. Otherwise you can run the script directly:

    my_python.py 1 3 2

With pylauncher (py.exe) installed to %WINDIR% you don't even need the
installation directory on PATH. See PEP 397.

http://www.python.org/dev/peps/pep-0397
http://bitbucket.org/vinay.sajip/pylauncher

I still add the scripts directory to PATH, which in your case might be
"C:\Python26\Scripts". I recommend you do this if you want
my_python.py to run as a command-line utility (of course you first
have to copy my_python.py to the scripts directory). You can even
avoid using the .py extension if you add .PY to the PATHEXT
environment variable.

Beyond the Windows details, your script needs to import sys and get
the argument list, sys.argv[1:]. The arguments are strings, so you'll
need to convert to float or int as required. Also, why do you import
the math module? You're not using it.


More information about the Tutor mailing list