how to determine if python is run interactively? (-i)

jfrancis4970 at jfrancis4970 at
Tue Jul 14 17:58:44 CEST 2009

how do you determine, from within a python program, whether the python
interpreter was launched in interactive mode? in other words, if i
have a program called "", i want to ensure that the program was
launched with this command line:

python -i

(and not just with "python"). the reason is that i'm doing
some very expensive and lengthy initialization in my program
that will be useless unless the program exits to the python prompt
when it is done, where the user can run further python commands.

obviously i can't use sys.argv since that is only for parameters
passed to the program, not for parameters passed to the python
interpreter itself. i haven't found a way to access these options...

any help would be greatly appreciated!

More information about the Python-list mailing list