Smith, Jeff wrote:
> I have an object and I want to call a method that I have constructed 
> the name for in a string.
>  
> For example:
> str_method = 'myfun'
> obj.str_method
>  
> Of course, this fails.  I know I could probably do this with exec but 
> is there a better way?
Use getattr():

getattr(obj, 'myfun')()

Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to