On 1/18/2013 3:00 PM, Steve Spicklemire wrote:
A related question. Is it possible for my module to detect that it's
being run under IDLE? Are there any clues in the environment that I
could count on to tell?

That is an interesting question. We try to make the answer 'no' as much as possible. But then I remembered (with 3.3, same on 2.7.3)

>>> import sys
>>> sys.stdin
<idlelib.run._RPCInputFile object at 0x0000000003137320>
>>> 'idlelib' in str(sys.stdin)
True

The module may not always been a part of the representation, so I will not guarantee that for anything previous. There is also

>>> sys.stdin.__module__
'idlelib.rpc'

and

>>> 'idlelib' in sys.modules
True

I like this best. It is False in the standard interpreter on startup and I am sure not stdlib module imports idlelib. So as long as your program does not (and there is no reason to) it should be safe.

--
Terry Jan Reedy

_______________________________________________
IDLE-dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/idle-dev

Reply via email to