LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Blogs > Snark1994
User Name
Password

Notices

Rate this Entry

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.

Code:
from sys import modules
print('In IDLE' if 'idlelib.run' in modules else 'Not in IDLE')
Posted in Uncategorized
Views 430 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 02:00 PM.

Main Menu

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration