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
Post a Comment