Detecting -i in a script

Chris Rebert clp2 at
Tue Apr 14 02:40:52 CEST 2009

> Marek Szuba wrote:
>> On 2009-04-13, Chris Rebert <clp2 at> wrote:
>>> The sys.flags.interactive bool.
>>> Details:
>> Hmm, "New in version 2.6"... Are you aware of any way of extracting
>> this information in older versions of Python? My code needs to be
>> 2.3-compatible.

On Mon, Apr 13, 2009 at 5:32 PM, Static Vagabond <static at> wrote:
> I think getopt will help you achieve what you need.

A. Please don't top-post. It makes following the conversation more
difficult by presenting it out of chronological order.

B. -i is an option to the Python interpreter *itself*, not the Python
script, and so gets gobbled up before the script even starts, thus
`getopt` won't work. Observe:

chris at morpheus ~ $ cat
from sys import argv
print argv
chris at morpheus ~ $ python -i

I have a blog:

More information about the Python-list mailing list