pep 308: why doing (almost) nothing suffices
Steven Taschuk
staschuk at telusplanet.net
Sun Mar 9 23:31:43 EST 2003
Quoth Edward K. Ream:
[...]
> def choose_eval(cond, a, b): # warning: evals all arguments
>
> if cond: return eval(a)
> else: return eval(b)
>
> Heavy duty stuff by my present bathtub standards. So to "delay" the
> evaluation of an argument, just quote it. Wow--just like lithp. Example:
>
> choose_eval(a < b,"foo(a)","spam(b)")
Hm. What about this little problem?
>>> def optional_reverse(s, reverse=0):
... return choose_eval(reverse, 's.reverse()', 's')
...
>>> optional_reverse('foo', 1)
[...]
NameError: name 's' is not defined
I suppose choose_eval could be special-cased to take implicit
arguments of the locals and globals of the calling context...
[...]
> P.P.S. All criticisms of this brilliant proposal are obviously impertinent,
> even if valid.
I am ashamed. Forgive me!
--
Steven Taschuk o- @
staschuk at telusplanet.net 7O )
" (
More information about the Python-list
mailing list