0

If I run the python script file from IDLE or Windows command prompt, I am able to view the error message.

Script file:

print(3/0)
input()

Error:

Traceback (most recent call last):
  File "...\TEST.py", line 1, in <module>
    print(3/0)
ZeroDivisionError: division by zero

But if I run the file by double clicking on it, the window just closes and I do not know what the error is. How can I see it?

I am running Python 3.4.

mcu
  • 3,302
  • 8
  • 38
  • 64

2 Answers2

0

If you just double-click the file, once you hit an error, it terminates the program, thus closing the console window. To see the errors, you should run it from the command prompt.

Sid
  • 11
  • 6
0

This is how its supposed to work. When you "doubleclick" the .py file windows sees an executable file and invokes a cmd-shell and runs your python executable within (even though its only a text file, its considered as an executable - thats how you have set it in your system - this can be changed, say to make a doubleclick simply open the file in a text editor of your choice, like Notepad or Notepad++ or Python's default IDLE editor). Since division by 0 is an error, the cmd-shell is killed as soon as the error is seen in the .py file - your .py file is treated as an executable, much like how an .exe application crash doesn't wait for you before its killed.

If you do not want lose the window and wish to see the error, then you already seem to know what to do - run it by invoking python from a cmd-shell manually, or better still, use the built-in IDLE editor (Press F5 to run your script from an IDLE editor)

Pranav Rai
  • 160
  • 4
  • 8