getattr on a function

Terry Reedy tjreedy at udel.edu
Mon Apr 27 15:01:06 EDT 2009


Mr SZ wrote:
> Hi all,
> 
> Is it possible to call functions using getattr. I have written a simple script with functions that call either SSL, TLS or plain functionality.
> 
> something like:
> def func():
>   ...
> 
> def funcSSL():
>   ...
> 
> def funcTLS():

funcs = {'none':func, 'SSL':funcSSL, 'TLS':funcTLS}
...
cryptfunc = funcs[ <expression yielding 'none', 'SSL', or 'TLS'> ]

>   ...
> 
> Now, based on my args I would like to call either one of them. In my case, I can't seem to figure out what my object would be when I call getattr(object, 'func'+<encryption>) !
> 
> " life isn't heavy enough,it flies away and floats far above action"
> 
> 
>       Enjoy a safer web experience. Upgrade to the new Internet Explorer 8 optimised for Yahoo!7. Get it now.
> --
> http://mail.python.org/mailman/listinfo/python-list
> 




More information about the Python-list mailing list