Tue, 5 Feb 2002 13:46:03 -0800
> -----Original Message-----
> From: Tim Wilson [mailto:firstname.lastname@example.org]
> On Sun, 3 Feb 2002, Callum Golding wrote:
> > I'm sorry to bother you, but i was wondering if you could
> > give me a little advice. I've recently downloaded Python 2.2.
> > Ive read a begginers guide to programming and tried creating
> > a small program, I used the input function. Now as soon as I
> > open the program it goes into dos and asks me the question,
> > and when i type in an anwser, dos shuts down. Now its really
> > starting to bug me. If you could give me some advice I would
> > be real grateful. The program I wrote is below; -
> It's no bother. The problem is that the DOS window is closing
> immediately upon your program exiting. Annoying, isn't it. :-)
> One way to "fix" this is to add an input line at the end of
> your program
> like this:
> end = raw_input("Press a key to end...")
> This will leave the window open until you press a key.
Another way to approach it is from the OS side. If you're using WinNT/2K/XP,
you can achieve the same effect using drag-and-drop with a batch file (I'm
assuming you're double-clicking on the .py file). It's a small one-liner, so
you could keep a copy in as many directories as you want. And just drop the
file you want to run onto the .bat file.
cmd.exe /k "C:\python21\python.exe %1"
The "/k" option tells cmd.exe to stay open after it has run the string
following it. In this case it's the Python interpreter, which gets passed
the expansion of "%1", which in drag-and-drop land is the name of the file
that got dropped (The quotes protect any spaces in the pathnames).
Win95/98 users could use:
command.com /c "C:\python21\python.exe %1"
This way, you're not adding something to your program just to cater to the
peculiarities one OS (something to consider if you're doing cross-platform
work). It's one less thing to clean up!
Hope that helps!