dynamic-attributes

Dynamically creating read-only attributes

Dynamically creating read-only attributes Question: I’m currently trying to create a class that inherits from set, but allows calling for subsets with attributes. Since I want to create this class such that I can use it in any context, I want to have it be able to create attributes from any given string. I have …

Total answers: 1

getattr() versus __dict__ lookup, which is faster?

getattr() versus __dict__ lookup, which is faster? Question: I can dynamically look up object attribute values using object.__dict__[some_key] or getattr(object, some_key). Which is faster or better, and why? >>> class SomeObject: … pass … >>> so = SomeObject() >>> so.name = ‘an_object’ >>> getattr(so,’name’) ‘an_object’ >>> so.__dict__[‘name’] ‘an_object’ Asked By: Cole || Source Answers: You …

Total answers: 1