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

jfrancis4970 at mailinator.com jfrancis4970 at mailinator.com
Tue Jul 14 11:58:44 EDT 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 "test.py", i want to ensure that the program was
launched with this command line:

python -i test.py

(and not just with "python test.py"). the reason is that i'm doing
some very expensive and lengthy initialization in my test.py 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 test.py 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