Search code examples
pythonexitpython-idleexit-code

How to remove exit(0) pop-up in Python IDLE?


I am trying to run some code on Python IDLE, but when I use exit() I am getting a pop-up. How can I remove this pop-up?

print "hi"
exit(-1)

Pop-up


Solution

  • Use exit() from sys module.

    import sys
    
    # your cool code here
    
    sys.exit(0) # stops the program without a pop-up
    

    For example in an if:

    import sys
    
    x = 2
    if x > 1:
        print "x > 1"
        sys.exit()
    else:
        print x