Interesting list Validity (True/False)

nufuhsus at gmail.com nufuhsus at gmail.com
Fri May 11 17:07:51 EDT 2007


On May 11, 4:32 pm, Grant Edwards <gra... at visi.com> wrote:
> On Fri, May 11, 2007 at 01:20:44PM -0700, nufuh... at gmail.com
> wrote:
>
> > On May 11, 3:55 pm, Grant Edwards <gra... at visi.com> wrote:
> > > You got those results because that's what your program does.
>
> > > Were you intending it to do something else?  If so, you're
> > > going to have to explain what you wanted, because we can't
> > According to my output, it seems that arg is False even when I
> > give an option of '-o' which according to the book should be
> > True. No?
>
> '-o' is not equal to True.  However, that does not mean it
> evaluates to false when tested by an if or while statement.
>
> > If arg == ['-o'] then shouldn't arg == True return True and
> > skip the if?
>
> No.  See the folloing link regarding the "truth value" of an
> object:
>
> http://docs.python.org/lib/truth.html
>
> There are many objects other than True that evaluate to "true"
> in the context of an if/while statement.  Just because an
> objecty has a "true" truth-value doesn't mean that it is equal
> to the True object.
>
> --
> Grant Edwards                   grante             Yow! Why don't you ever
>                                   at               enter any CONTESTS,
>                                visi.com            Marvin??  Don't you know
>                                                    your own ZIPCODE?

OK. Then how would you differenciate between a call with an option
versus one without (e.g. help.py -o (where arg == ['-o']) Vs. help.py
(where arg == []))?




More information about the Python-list mailing list