Dynamically call methods where method is known by address vs name

Malcolm Greene python at bdurham.com
Fri Jul 22 16:04:28 EDT 2016


I know I can do the following:
 
>>> s = 'lower'
>>> getattr(s, 'upper')()
'LOWER'
 
But how could I do the same if I had the method 'address' (better
name???) vs. method name?
 
>>> upper_method = s.upper
 
How do I combine this upper_method with string s to execute the method
and return 'LOWER'?
 
Thank you,
Malcolm
 
 



More information about the Python-list mailing list