Python - check if in IDLE
Posted 10-01-2011 at 05:28 AM by Snark1994
Another useful thing which I didn't realise before:
How do you get your python programme to check if it's running in IDLE or in the terminal? I tend to use the IDLE in Windows for debugging, and run programmes by double clicking so they open in the terminal.
There's not much difference between the two, but 'print'ing is slower in IDLE, and you can't use '\r' to overwrite things already printed.
Luckily, there's an easy way to check.
How do you get your python programme to check if it's running in IDLE or in the terminal? I tend to use the IDLE in Windows for debugging, and run programmes by double clicking so they open in the terminal.
There's not much difference between the two, but 'print'ing is slower in IDLE, and you can't use '\r' to overwrite things already printed.
Luckily, there's an easy way to check.
Code:
from sys import modules print('In IDLE' if 'idlelib.run' in modules else 'Not in IDLE')
Total Comments 0