How Do I Get An Attribute From An Object If I Have The Attribute Name In A String?
class a : b = 10 I have a class 'a' with attribute 'b'. o = a() I create a object 'o' of class 'a' v = 'b' I have another variable 'v' having the string representation
Solution 1:
Are you looking for something like this?
getattr(o, v)
Solution 2:
Use the built-in getattr
function:
getattr(o, v)
Post a Comment for "How Do I Get An Attribute From An Object If I Have The Attribute Name In A String?"