Finding out that Python is in interactive mode in

Joonas Paalasmaa joonas at
Fri Dec 28 17:43:16 EST 2001

Carey Evans <careye at> wrote in message news:<87g05wgq84.fsf at>...
> Joonas Paalasmaa <joonas at> writes:
> > How can I find out that Python is started in interactive mode in
> > ?
> A search on for "python test interactive"
> comes up with this as the second result:
>     import sys
>     if hasattr(sys, "ps1"):
>         # probably interactive
>     else:
>         # probably not interactive

For some reason it doesn't work in .
When these lines are to and Python is started in
interactive mode, Python prints "In non-interactive mode".

# the lines
import sys
if hasattr(sys, "ps1"):
    print "In interactive mode"
    print "In non-interactive mode"

More information about the Python-list mailing list