Can I check if I'm running from the interpreter prompt?
Peter Otten
__peter__ at web.de
Fri Nov 14 16:49:35 EST 2008
skip at pobox.com wrote:
> Is there a reliable way (this is on Solaris if that matters) to tell if
> I'm
> running in the interactive interpreter as opposed to in a script? I think
> examining sys.argv works, but wanted to double check.
hasattr(sys, "ps1")
http://www.python.org/doc/2.5.2/lib/module-sys.html#l2h-5167
"""
ps1
ps2
Strings specifying the primary and secondary prompt of the interpreter.
These are only defined if the interpreter is in interactive mode.
"""
More information about the Python-list
mailing list