Caution newbie question: python window to stay open ?

M

mkengel

Caution: newbie question

I am using python 2.4.3-11 on Windows XP.
Problem: Python window closes immediately after executing a *.py file
(e.g. containing a "print..." command.
What do I have to do to keep it open to see the results ?

"Interactive window" stays open.

Thank you.
Michael
 
F

Fredrik Lundh

mkengel said:
Problem: Python window closes immediately after executing a *.py file
(e.g. containing a "print..." command.
What do I have to do to keep it open to see the results ?

Simple scripts that print to a console, or read from it, works best if
you run them from a standard Command Prompt window.

If you just click on a Python script in the explorer, Windows will
create a temporary command window, and remove it when the program is
done. This is standard Windows behaviour; to get around this in a
general way, you need to write GUI-oriented Python programs (using e.g.
Tkinter or wxPython), and run them using the "pythonw.exe" runtime.

For simpler scripts, you can also add

raw_input("Press return to close this window...")

to the end of the script.

For tips on running Python programs from the command prompt, this page
might also be helpful:

http://effbot.org/pyfaq/how-do-i-run-a-python-program-under-windows

</F>
 
J

jim-on-linux

Michael,

put this at the top of your code. After the window
closes read the testLog.out file. It may give you
a clue as to what is happening.

sys.stdout = open('testLog.out', 'w')


jim-on-linux
http://www.inqvista.com
 
Joined
Jun 26, 2009
Messages
1
Reaction score
0
Use the /K option

the cmd.exe program has /K switch which holds the window open by returning to a command prompt.


Some text editors will have the ability to configure tools, so you can modify something like this:

C:\Windows\System32\cmd.exe /K X:\Python2.6.2\python.exe "%FILE%"

for your own system
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top