Hi all,
I have extended a prototype idea from Alex Martelli's resource on
metaclasses regarding time stamping of instances.
<code>
import time
class Meta(type):
start = time.time()
def __call__(cls, *args, **kw):
print 'Meta start time %e'%cls.start
x = super(Meta, cls).__call__(*args, **kw)
current_time = time.time()
x._created = current_time - Meta.start
Meta.start = time.time()
return x
class X(object):
__metaclass__ = Meta
class Y(X):
__metaclass__ = Meta
pass
a = X()
print 'a time stamp %e'%a._created
b = Y()
print 'b time stamp %e'%b._created
print abs(a._created - b._created)
</code>
I donot understand the difference between
1) setting __metaclass__ to 'Meta' in class Y
2) not setting __metaclass__ to Meta in class Y
Why is the difference in behaviour of time stamping between 1 & 2 ?
kindly enlighten
regards,
KM
--
http://mail.python.org/mailman/listinfo/python-list