Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What code can I use to check if script is running in IDLE?

Tags:

People also ask

How do I test code in IDLE?

To execute a file in IDLE, simply press the F5 key on your keyboard. You can also select Run → Run Module from the menu bar. Either option will restart the Python interpreter and then run the code that you've written with a fresh interpreter.

How do I know if my code is running in Spyder?

In Spyder you can tell whether a script is running by looking at the small square in the top right of the console window. If a script is running its red, else its grey.


Just as the title says. I want to write a script that behaves differently depending on whether it's running inside a console window or in IDLE. Is there an object that exists only when running in IDLE that I can check for? An environment variable?

I'm using Python 2.6.5 and 2.7 on Windows.

Edit:

The answers given so far work. But I'm looking for an official way to do this, or one that doesn't look like a hack. If someone comes up with one, I'll accept that as the answer. Otherwise, in a few days, I'll accept the earliest answer.