Python dynamic function selection

Eric ekoome at yahoo.com
Wed May 12 04:42:02 EDT 2004


The following example will explain what i want to do:
>>> def func():
	print "true"
>>> rules=(func,)
>>> for rule in rules:
        rule

I expect the final function to print true, but instead i have
<function func at 0x00DC6EB0>

How do i get it to print true. I know if i had parameters in rule
like:
>>> def func(var):
	print var
>>> rules=(func,)
>>> for rule in rules:
        rule("true")
it will work. But in my case i don't need to pass any parameters.

How do i get the former method to print instead of returning a
function?

Eric



More information about the Python-list mailing list