IDLE detection code snippet
Jesse W
jessw at loop.com
Mon Feb 18 01:27:37 EST 2002
Dear IDLE-devl members,
A problem that has been faced by people many times is that of
detecting when IDLE is running. I think this code is a solution to
that problem. Please try it out and see if it works consistently.
Jesse Weinstein
def IDLEtest():
"""Returns 1 when IDLE is running, 0 else.
Please let me know (through the IDLE-devl list) if you find
a situation where this gives the wrong answer."""
import sys
try:
if sys.stdin.__module__=='PyShell':
return 1
else:
return 0
except AttributeError:
return 0
More information about the Python-list
mailing list