Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

2 views
Skip to first unread message

jfranc...@mailinator.com

unread,
Jul 14, 2009, 11:58:44 AM7/14/09
to
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!

Duncan Booth

unread,
Jul 14, 2009, 12:26:28 PM7/14/09
to
jfranc...@mailinator.com wrote:

> how do you determine, from within a python program, whether the python
> interpreter was launched in interactive mode?

sys.flags.interactive or sys.flags.inspect

0 new messages