LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 1283 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 08:52 AM.

Main Menu
Advertisement
Advertisement
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
Open Source Consulting | Domain Registration