Running Scripts vs Interactive mode

Benjamin Kaplan benjamin.kaplan at case.edu
Thu Feb 24 10:53:25 EST 2011


On Thu, Feb 24, 2011 at 10:34 AM, grobs456
<gregory.alexander.roberts at gmail.com> wrote:
> c:\dev\python>python HelloWorld.py
> 'python' is not recognized as an internal or external command,
> operable program or batch file.
>
> #I then tried this for a success!:
>
> c:\dev\python>c:\python27\python.exe HelloWorld.py
> Hello WOrld!
>
> c:\dev\python>python HelloWorld.py
> 'python' is not recognized as an internal or external command,
> operable program or batch file.
>
>
> #I will utilize the advice regarding using IDLE but would like to
> figure out how to do the above.
> #Would this help me, per the tutorial?:
> chmod +x HellowWorld.py
>

No. That's for POSIX systems (Mac OS X, Unix, Linux) where you want to
execute the script just by typing ./HelloWorld.py rather than python
HelloWorld.py. The chmod tells the system that you're allowed to
execute that file directly.

> #I set my system environment variables to:
>
> VARIABLE                VALUE
> PYTHON_HOME             c:\python27\python.exe
> PATH                    ...;%PYTHON_HOME%
>
> #after also trying this:
> VARIABLE                VALUE
> PYTHON_HOME             c:\python27
> PATH                    ...;%PYTHON_HOME%
>

Apparently your PATH isn't getting set properly. If C:\Python27 is on
the path, it should find Python just fine. It works on my machine.

> #ALSO, I was confused by the following:
> Add into each your *.py script and as the very last line this:
> raw_input('Press any key to exit...')
>
> #Thanks for all the assistance thus far.
>


This is for when you try to execute a script by double-clicking on the
file. Every Windows console application will spawn a command prompt
when they are run (assuming they aren't run from the command prompt).
If they are launched this way, that command prompt will close
immediately when the program finishes. By putting a raw_input at the
end, you make the program wait for you to enter something before it
finishes, so the terminal window will stay open and you can read your
program's output.



More information about the Python-list mailing list