Can I check if I'm running from the interpreter prompt?

Scott David Daniels Scott.Daniels at Acm.Org
Fri Nov 14 21:36:08 CET 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.

     import sys, traceback

     try:
         raise ValueError
     except ValueError:
         start = traceback.extract_tb(sys.exc_info()[2])[-1]

Start should show you where the program is being run from.


--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list