PEP 308: A PEP Writer's Experience - PRO
Bernhard Herzog
bh at intevation.de
Tue Feb 11 10:58:25 EST 2003
I wrote:
> > > holger krekel wrote:
> > >
> > > > because it easily leads to
> > > >
> > > > if obj.method() if hasattr(obj, 'method') else None:
> > > >
> > > > which you have a harder time to justify as nice, not?
>
> Almost everybody -- and especially programmers coming from C! -- will
> write that as
>
> if hasattr(obj, 'method') and obj.method():
>
> In C && and || are short circuiting but they always evaluate to 0 or 1.
> The do not evaluate to one of their arguments as in Python.
That's what I get when trying to shorten my reply :(. The arguments
about C's && and || obviously don't really apply to Holger's if
statement above. The main point that the version with "and" is what most
programmers will use still stands, though.
Bernhard
--
Intevation GmbH http://intevation.de/
Sketch http://sketch.sourceforge.net/
MapIt! http://www.mapit.de/
More information about the Python-list
mailing list