Python paradigms

Ben Wolfson rumjuggler at home.com
Sun Apr 16 13:35:46 EDT 2000


On Sun, 16 Apr 2000 04:17:22 -0600, "Andrew Dalke" <dalke at acm.org>
wrote:

>You can imagine:
>
>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") + ...

I did this.  Instead of the nasty code to get the locals of the
calling function, you can change the parameter list to

def expression_if(test, true_string, false_string, gbals, lcals):

and pass in globals and locals when you call it.

-- 
Barnabas T. Rumjuggler

Half our days we pass in the shadow of the earth; and the brother of
death exacteth a third part of our lives.
 -- Thomas Browne.



More information about the Python-list mailing list