Python paradigms

Michael Hudson mwh21 at cam.ac.uk
Sun Apr 16 13:31:52 EDT 2000


"Andrew Dalke" <dalke at acm.org> writes:

> def expression_if(test, true_string, false_string):
>   # some nasty code to get the locals of the calling function
>   if test:
>     return eval(true_string with the given locals)
>   else:
>     return eval(false_string with the given locals
> 
> x = expression_if(a is not None, "a[i].weeble", "0") + ...
> 
> but that's just too ugly.

bytecodehacks can do this (except that the relavent bits seem to have
suffered bit-rot; I'll do something about that presently).

I also can't remebmer how that bit of bytecodehacks works (! - just as
well I wrote docs <wink>).

Cheers,
M.

-- 
  "declare"?  my bogometer indicates that you're really programming
  in some other language and trying  to force Common Lisp into your
  mindset.  this won't work.           -- Erik Naggum, comp.lang.lisp



More information about the Python-list mailing list