Python Metaclasses -- attributes not visible
I'm trying to create 2 objects, 1) A by defining as a regular Python class
2) B by dynamically creating properties.
Once both the classes are created, Im trying to print their dictionary and
noticed that for Class B which is dynamically created the attribute "X" is
not listed.
class A(object):
def __init__(self,x,y):
self.x = 0
self.y = 0
x = A(1,2)
print "Class A directory =",dir(x)
class B:pass
B().x = 5
y = B()
print "Class A directory =",dir(y)
OUtput
Class A directory = ['__class__', '__delattr__', '__dict__', '__doc__',
'__format__', '__getattribute__', '__hash__', '__init__', '__module__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'x', 'y']
Class B directory = ['__doc__', '__module__']
No comments:
Post a Comment