How a script can know if it has been called with the -i commandlineoption?
Hendrik van Rooyen
mail at microcorp.co.za
Sat Dec 23 00:26:29 EST 2006
"Michele Simionato" <michele.simionato at gmail.com> wrote:
> Hendrik van Rooyen wrote:
> > "Michele Simionato" <michele.simionato at gmail.com> wrote:
> > > but I don't see a way to retrieve the command line flags, where should
> > > I look?
> >
> > sys.argv() ?
> >
> > - Hendrik
>
> No, read what Carsten said:
> """
> 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.
> """
True. - I was under the impression that sys.argv has all the stuff in it,
but it just ain't so - I made a file called junk.py containing two lines:
import sys
print sys.argv
and sys.argv just has junk.py in it, for both styles of command line.
I also noticed that if you do the following:
python junk.py -i
then the interpreter is not interactive. I was also not aware that
the options had positional dependency.
you could do a work around by calling it like this:
python -i junk.py -i
then sys.argv has the extra -i...
or better, insist on being told in both cases with say -i and -n at the end.
it does not answer the real question, though, as someone could lie to you.
- Hendrik
More information about the Python-list
mailing list