Typically, a Python handle is defined as class attributes. But in my case, I want each instance of the object to have different set descriptors that depend on the input. For example:
class MyClass(object): def __init__(self, **kwargs): for attr, val in kwargs.items(): self.__dict__[attr] = MyDescriptor(val)
Each object has a different set of attributes, which are defined during instance creation. Since these are disposable objects, do not first subclass them.
tv = MyClass(type="tv", size="30") smartphone = MyClass(type="phone", os="android") tv.size
Assigning a handle to an object does not seem to work. If I try to access the attribute, I got something like
<property at 0x4067cf0>
Do you know why this does not work? Is there any work around?
python metaprogramming
Wai yip tung
source share