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

J

jfrancis4970

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top