Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How do you stop the program from just closing once its done.

maxiscoolmaxiscool Posts: 2Member
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?

Comments

  • infidelinfidel Posts: 2,900Member
    : 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.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • maxiscoolmaxiscool Posts: 2Member
    : : 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.
    :
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    : [code]
    : $ select * from users where clue > 0
    : no rows returned
    : [/code]
    :
    :
    Thanks that did the trick. Do you mind explaining how that works?
  • infidelinfidel Posts: 2,900Member
    [b][red]This message was edited by Moderator at 2004-7-23 10:36:7[/red][/b][hr]
    : : 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...
    ')


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]



  • ewoud1989ewoud1989 Posts: 1Member
    : : 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.
    :
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    : [code]
    : $ select * from users where clue > 0
    : no rows returned
    : [/code]
    :
    :

  • Gregry2Gregry2 Posts: 607Member
    : I forgot about a pure python way of doing the same thing:
    :
    : raw_input('Press ENTER to continue...
    ')
    :

    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
  • infidelinfidel Posts: 2,900Member
    : : I forgot about a pure python way of doing the same thing:
    : :
    : : raw_input('Press ENTER to continue...
    ')
    : :
    :
    : 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.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

Sign In or Register to comment.