Python style guidelines

John Roth newsgroups at jhrothjr.com
Thu Mar 11 12:16:54 EST 2004


"Peter Hansen" <peter at engcorp.com> wrote in message
news:EO%3c.2675$G3.20988 at localhost...
> Josef Meile wrote:
> >>>>>> a='test'
> >>>>>> if a.find('foo'):
> >>>
> >>>
> >>> ...    print "foo was found"
> >>> ...
> >>> foo was found
> >>
> >>
> >>
> >> a.find does not return a boolean, so that particular style guideline
> >> does not apply.
> >
> > I know, but I found this on the Zope source, which
> > means that there is people thinking that the False
> > on python includes negative values.
>
> I believe it's more likely they just forgot what find() did return, as
> they were writing the code.  I've done the same, thinking it was a
> boolean, not thinking that it returned a negative but that negatives
> were considered false.

I suspect that's a rather common error. I'd much prefer
that both find and index return an object that acted like
a number but returned the logically correct response when
queried as a boolean: true for zero and false for -1. Also,
the "not found" object should throw an exception if it's
used as an index or slice.

John Roth
>
> -Peter





More information about the Python-list mailing list