Python

Moderators: None (Apply to moderate this forum)
Number of threads: 474
Number of posts: 1166

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How do you stop the program from just closing once its done. Posted by maxiscool on 21 Jul 2004 at 4:58 PM
Hello, I just started learning how to program about an hour ago and I when I make a program it just closes once its done when I run it. How can I get it to pause or something when its done?
Report
Re: How do you stop the program from just closing once its done. Posted by infidel on 22 Jul 2004 at 11:43 AM
: Hello, I just started learning how to program about an hour ago and I when I make a program it just closes once its done when I run it. How can I get it to pause or something when its done?

If you're talking about running a python script in MSWindows where the console window closes once the script is finished, then you can do something like:

import os
os.system("pause")

If you mean something else then you'll have to be more specific.


infidel

$ select * from users where clue > 0
no rows returned


Report
Re: How do you stop the program from just closing once its done. Posted by maxiscool on 22 Jul 2004 at 6:02 PM
: : Hello, I just started learning how to program about an hour ago and I when I make a program it just closes once its done when I run it. How can I get it to pause or something when its done?
:
: If you're talking about running a python script in MSWindows where the console window closes once the script is finished, then you can do something like:
:
: import os
: os.system("pause")
:
: If you mean something else then you'll have to be more specific.
:
:
: infidel
:
:
: $ select * from users where clue > 0
: no rows returned
: 

:
:
Thanks that did the trick. Do you mind explaining how that works?
Report
Re: How do you stop the program from just closing once its done. Posted by infidel on 23 Jul 2004 at 10:29 AM
This message was edited by Moderator at 2004-7-23 10:36:7

: : import os
: : os.system("pause")
: :
: Thanks that did the trick. Do you mind explaining how that works?

The os module is a way for python to interact with the operating system. The system function passes a command line to the operating system. On MSWindows, the "pause" command waits for the user to press enter (i.e. in batch files). Try passing any DOS command to os.system to see what happens.

I forgot about a pure python way of doing the same thing:

raw_input('Press ENTER to continue...\n')


infidel

$ select * from users where clue > 0
no rows returned




Report
Re: How do you stop the program from just closing once its done. Posted by Gregry2 on 25 Aug 2006 at 3:09 AM
: I forgot about a pure python way of doing the same thing:
:
: raw_input('Press ENTER to continue...\n')
:

Is this okay python programming, or just a simple way to get around? This is like using fgetc(stdin) in C/C++ to pause, which doesn't really make sense but is simply used for such. But of course, it doesn't make sense because its C/C++, but in python, I'd expect such stuff to not be considered bad programming...

{2}rIng
Report
Re: How do you stop the program from just closing once its done. Posted by infidel on 25 Aug 2006 at 7:43 AM
: : I forgot about a pure python way of doing the same thing:
: :
: : raw_input('Press ENTER to continue...\n')
: :
:
: Is this okay python programming, or just a simple way to get around? This is like using fgetc(stdin) in C/C++ to pause, which doesn't really make sense but is simply used for such. But of course, it doesn't make sense because its C/C++, but in python, I'd expect such stuff to not be considered bad programming...

As far as I know it's not considered bad form.


infidel

$ select * from users where clue > 0
no rows returned


Report
Re: How do you stop the program from just closing once its done. Posted by ewoud1989 on 24 Aug 2006 at 2:24 PM
: : Hello, I just started learning how to program about an hour ago and I when I make a program it just closes once its done when I run it. How can I get it to pause or something when its done?
:
: If you're talking about running a python script in MSWindows where the console window closes once the script is finished, then you can do something like:
:
: import os
: os.system("pause")
:
: If you mean something else then you'll have to be more specific.
:
:
: infidel
:
:
: $ select * from users where clue > 0
: no rows returned
: 

:
:




 

Recent Jobs