How a script can know if it has been called with the -i command line option?

Carsten Haese carsten at uniqsys.com
Thu Dec 21 14:45:18 EST 2006


On Thu, 2006-12-21 at 11:22 -0800, commander.coder at hotmail.com wrote:
> Michele Simionato wrote:
> > The subject says it all, I would like a script to act differently when
> > called as
> > $ python script.py and when called as $ python -i script.py. I looked
> > at the sys module
> > but I don't see a way to retrieve the command line flags, where should
> > I look?
> In the optparse module.

That doesn't answer the question. The OP wants to inspect the options
passed to the interpreter, not the options passed to the script.
optparse aids in parsing sys.argv, which only contains the options that
are passed to the script.

-Carsten





More information about the Python-list mailing list