-1

I wrote a simple code to print , "hello world" in Python. As I execute it , the terminal window pops up and closes within a second , even before I can read the message. Possibly , what is wrong ?

falsetru
  • 357,413
  • 63
  • 732
  • 636
  • 1
    (Probably) nothing is wrong; the terminal window closes when the program finishes. – jonrsharpe Jul 13 '14 at 11:22
  • 1
    Please read some book about python, search before you ask a question. Nothing went wrong. It just printed your text and closed the terminal because it is finished. – Salvador Dali Jul 13 '14 at 11:22
  • [Could we please be a bit nicer to new users?](https://meta.stackexchange.com/questions/9953/could-we-please-be-a-bit-nicer-to-new-users). – jww Jul 13 '14 at 11:47
  • You haven't mentioned the operating system and how are you executing it. I'm not having this problem on Linux, so how do I reproduce it? :-D Also how about doing some research first. If I search "Python program closes quickly" with Google, some interesting results pop at the top e.g. [How can I stop python.exe from closing immediately after I get an output?](http://stackoverflow.com/q/3591807/12892) or [How do I prevent my Python 2.6 application from automatically closing once reaching the end of code?](http://stackoverflow.com/q/2322868/12892). Maybe you should create a canonical question. – Cristian Ciupitu Jul 13 '14 at 12:39
  • Errata: **we** the Stack Overflow community, not you the one who asked. – Cristian Ciupitu Jul 13 '14 at 20:50

4 Answers4

1

If you run the program in windows, as far as there are two workarounds:

  • Run the program in command prompt (cmd.exe, powershell) instead of double clicking the script file.
  • Modify the script to include input() at the end of the script (to make the script wait for user input)
falsetru
  • 357,413
  • 63
  • 732
  • 636
0

You could make it to ask you a question like :

var = input("Please enter something: ")

So it won't immediately close.

0

If you are on Windows and do not want to change your program, start it by double-clicking a batch file, called RUNHELLO.BAT containing this:

python helloworld.py
PAUSE
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
-1

first I think you should wirte "Hello world" in this section:

if __name__ == '__main__':
   print("Hello World!");

then you should run this command "python helloworld.py" in terminal.

Hope help you.

meepo
  • 11
  • 5