[Idle-dev] IDLE detection code snippet
Fred Drake
fdrake@zope.com
Mon, 18 Feb 2002 11:06:44 -0500
On Sun, 17 Feb 2002 22:27:37 -0800
"Jesse W" <jessw@loop.com> wrote:
> detecting when IDLE is running. I think this code is a
> solution to
> that problem. Please try it out and see if it works
...
> 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
Simplify:
def IDLEtest():
import sys
try:
return sys.stdin.__module__ == 'PyShell'
except AttributeError:
return 0
-Fred
--
Fred L. Drake, Jr. <fdrake at acm.org>
PythonLabs at Zope Corporation