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

I would prefer to do:

import sys
print('Running IDLE' if 'idlelib.run' in sys.modules else 'Out of IDLE')

Leave a Comment