function - Substitute class method with a string in Python -


lets want this

hashlibalgo = "md5" hash= hashlib.**"hashlibalgo"**("blah blah blah").hexdigest() 

how can that. if substitute name of method string not work. how can make work? in powershell easy, cannot figure in python.

you can function execute getattr:

>>> import hashlib >>> hashlibalgo = "md5" >>> getattr(hashlib, hashlibalgo)("blah blah blah").hexdigest() '55e562bfee2bde4f9e71b8885eb5e303' 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -