Python dynamic function selection
Shalabh Chaturvedi
shalabh at cafepy.com
Wed May 12 09:27:09 EDT 2004
Eric wrote:
> 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>
>
<another example snipped>
> How do i get the former method to print instead of returning a
> function?
>
> Eric
As others have mentioned, you have to use parenthesis () to call
anything, function or otherwise.
The function name by itself referes to the function. This feature allows
functions to be used as first-class objects easily - they can be passed
around like data.
def f():
print 'true'
g = f
g()
HTH,
Shalabh
More information about the Python-list
mailing list