Feature suggestion -- return if true
mwilson at the-wire.com
Tue Apr 12 17:12:09 CEST 2011
Paul Rubin wrote:
> zildjohn01 <zildjohn01 at gmail.com> writes:
>> _temp = expr
>> if _temp: return _temp
> I'm trying to figure out a context where you'd even want that, and I'm
> thinking that maybe it's some version of a repeat-until loop? Python
> doesn't have repeat-until and it's been proposed a few times.
I can imagine
although my real code would probably be more like
if tree_node.left is not None:
return "left", tree_node.left
if tree_node.right is not None:
return "right", tree_node.right
where adding the "left" and "right" markers makes the return? feature
impossible to use.
The proposed feature reminds me of the `zod` function (was that the actual
name?) that returned 0 rather than bringing on a ZeroDivideError. It would
cement a strange corner-case into the language.
More information about the Python-list