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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -