Greg Ewing <greg.ewing <at> canterbury.ac.nz> writes:

> 
> Raymond Hettinger wrote:
> > I propose that in Py3.0, the "and" and "or" operators be simplified to
> > always return a Boolean value instead of returning the last evaluated
> > argument.
> 
> But then I would no longer be able to write
> 
>    foo = something or default_value
> 
> which is one of my favourite Pythonisms!

Same here.  I use this frequently.  In fact, I sometimes use it in preference
to a default param in {}.get():

    foo = somedict.get("blarg") or expensive_default()

That way the expensive default isn't calculated unless you need it.  (Of
course, the dict has to only store values that evaluate to non-False, which
might not be possible in all situations.)

Skip


_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to