How to tell if interpreter is in interactive mode

John Copella jcopella at cfl.rr.com
Wed Jun 13 04:33:58 EDT 2001


I have some code in a module that I need to run only when the interpreter is
running interactively.  Is there any way to test for this at run time?  I
have looked at sys.stdin.isatty(), but this returns 1 when running
non-interactively as well (unless you do something odd like redirect stdin
to /dev/null).

Thanks in advance,

John






More information about the Python-list mailing list