Passing to a function -- object and method names (or references)

Midas M at a.k
Fri Jan 2 15:17:41 EST 2004


Peter Otten wrote:

>You can access attributes with the getattr() builtin.
>
>carGas = getattr(car, "gas")
>
>You can refer to a method either directly 
>
>fun = car.drive 
>fun(123)
>
>or via getattr():
>
>fun = getattr(car, "drive")
>fun(321)
>
>I've modified your example to demonstrate this. 

Thank you very much, Peter! It works nicely!

Midas



More information about the Python-list mailing list