indirect function calls and variable variables
Randall Smith
randall at tnr.cc
Wed May 21 00:35:55 EDT 2003
Question: Is it feasible to make indirect function calls in python?
Example:
def f1():
blah blah
blah blah
def f2():
foo doo
doo foo
def f3():
yik yak
mee yow
def fInfinity():
yo yo
yaw yaw
#what i'm trying to avoid
def do_f(f):
if f == 'f1': f1()
if f == 'f2': f2()
if f == 'f3': f3()
if f == 'fInfinity': youGetThePoint()
#what i'd like to do instead
def do_f(f):
f() # this doesn't work, but maybe you get the point.
While I'm at it, can Python do variable variables?
In PHP:
$var = 'hey'
$$var = 'dude'
echo $dude
output: hey
I used this alot in PHP. Is there a way to do it in Python?
Randall
More information about the Python-list
mailing list