Actually, what I wanted was to be able to reference the variable being assigned to


On Thu, Jul 11, 2013 at 7:07 PM, David Mertz <mertz@gnosis.cx> wrote:
On Thu, Jul 11, 2013 at 4:57 PM, Joao S. O. Bueno <jsbueno@python.org.br> wrote:
I don't know if what I miss most is the samething the OP is asking for -
but the idea of re-using a value retrieved in an expression in the
same expression - without the need
to assign to a temporary variable.

Like in:
  value = expensive_function(b)  if expensive_function(b) else default_value

(of course this is a trivial example - but nonetheless it would require an
extra "if" statement to avoid the double call)

How about:

  value = expensive_function(b) or default_value

One call, exact same behavior as you request.  Available since Python 1.0.


--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
http://mail.python.org/mailman/listinfo/python-ideas




--
Corey Sarsfield