Python dynamic function selection

Marijan Tadin mtadin66 at yahoo.com
Wed May 12 03:58:31 EDT 2004


for rule in rules:
    rule()




"Eric" <ekoome at yahoo.com> wrote in message
news:b0457a31.0405120042.31f97c at posting.google.com...
> 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