Running Scripts vs Interactive mode

G

grobs456

Hi,

I am trying to work through the tutorial at: http://docs.python.org/tutorial/

The issue I am facing is with regards to the discussion about
"Invoking the Interpreter" and "Executable Python Scripts". It was
rather hazy in my opinion.

see: http://docs.python.org/tutorial/interpreter.html

I realize I can double click on a .py file and Windows treats it as an
executable but the command prompt pops in and out so quickly that I
can't see the results of my script.


I would prefer to follow along with the tutorial, compiling new ticks
and topics into a growing .py file, that I error check of course(in
case the same variables are used throughout the tutorial), and then
run that file to see the results as if I would have typed each line in
one at a time. This way I have something usable to refer back to for
learning purposes and for future coding projects instead of having to
rely on the tutorial itself for my reference moving forward. Any
ideas?

Python is installed at:
C:\Python27

and I ran:
set path=%path%;C:\python27

#do i have to run the above each time I open up a session?
#Also, note that I do not see the any system environment variables
get updated when I run the above.
 
N

n00m

Add into each your *.py script and as the very last line this:
raw_input('Press any key to exit...')

Or, even better, I'd recommend this free Python Editor:
http://pythonide.stani.be/
SPE IDE - Stani's Python Editor
Free python IDE for Windows,Mac & Linux with UML,PyChecker,Debugger,
GUI design,Blender & more

A superb thing, imo.

But firstly download and install python package *wxPython*:
wxPython2.8-win32-unicode-2.8.11.0-py25.exe

SPE Editor needs it to work properly.
 
T

Terry Reedy

Hi,

I am trying to work through the tutorial at: http://docs.python.org/tutorial/

The issue I am facing is with regards to the discussion about
"Invoking the Interpreter" and "Executable Python Scripts". It was
rather hazy in my opinion.

An alternative to the other solutions given is to edit in an IDLE editor
window and run with F5. Results are printed in the Shell window and when
the script is finished, you can interactively examine any object created.
 
D

Dave Angel

Don't do that, then :)

You can open a persistent terminal window, and run the program from the
command line.

You get at least three other benefits: You can specify arguments
(available in sys.argv) for each run, to test the program in various
ways. And you can see earlier runs on the screen, and scroll back an
arbitrary (configurable) amount to see what changed. And you can
copy/paste that output elsewhere, like to an email if you have a question.


The value will survive within the one command window, and any other
command windows you start from it. But if you want that value to be
available on all (new) command windows, you set it in the Control Panel.
It's been a while since I ran Windows, but it was someplace like
System->EnvironmentVariables) Once you do that, it'll not only be
available in any new DOS sessions, and any application that's run from
Explorer, but also will survive a restart.

DaveA
 
S

scattered

Hi,

I am trying to work through the tutorial at:http://docs.python.org/tutorial/

The issue I am facing is with regards to the discussion about
"Invoking the Interpreter" and "Executable Python Scripts". It was
rather hazy in my opinion.

see:http://docs.python.org/tutorial/interpreter.html

I realize I can double click on a .py file and Windows treats it as an
executable but the command prompt pops in and out so quickly that I
can't see the results of my script.

I would prefer to follow along with the tutorial, compiling new ticks
and topics into a growing .py file, that I error check of course(in
case the same variables are used throughout the tutorial), and then
run that file to see the results as if I would have typed each line in
one at a time. This way I have something usable to refer back to for
learning purposes and for future coding projects instead of having to
rely on the tutorial itself for my reference moving forward. Any
ideas?

Python is installed at:
C:\Python27

and I ran:
set path=%path%;C:\python27

#do i have to run the above each time I open up a session?
#Also, note that  I do not see the any system environment variables
get updated when I run the above.

Greetings,

I too have been learning Python on Windows in recent months. I have
found using IDLE more than adequate for my purposes. When you right-
click on a .py file "Edit with IDLE" is one of the options (if you
have a standard Python install). Selecting "run" from IDLE opens up a
Python shell and runs the script. Alternatitively, you can open IDLE
directly then load your script into it. Unless you need to directly
enter Windows commands at a DOS prompt, running scripts from IDLE's
Python shell makes for a superior command line for Python, since it is
syntax aware (e.g. helps with code indentation) and allows for easy
cut-and-paste of previously typed commands. IDLE is a bit clunky
compared to commerical IDEs, but is excellent for doing quick
experiments.
 
G

grobs456

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

#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%

#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.
 
B

Benjamin Kaplan

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.
 
D

Dave Angel

<snip>
#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%

The latter should be correct. But how are you actually setting them?
In the Control Panel? And have you checked that they're actually set,
by typing
PATH

at the command prompt, of a newly created DOS box? The path should
consist of a number of directory locations, separated by semicolons
(this is Windows).


DaveA
 
G

grobs456

The latter should be correct.   But how are you actually setting them?
In the Control Panel?  And have you checked that they're actually set,
by typing
   PATH

at the command prompt, of a newly created DOS box?  The path should
consist of a number of directory locations, separated by semicolons
(this is Windows).

DaveA

The issue was that I needed a new DOS box. Thanks everyone!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top