derived class name in python 2.6/2.7
d at davea.name
Wed Jan 30 21:20:33 CET 2013
On 01/30/2013 03:05 PM, Sells, Fred wrote:
> This is simple, but I just cannot find it after quite a bit of searching
> I have this basic design
> class A:
> def __init__(self):
> print 'I am an instance of ', self.__class__.name
> class B(A):
> X = B
> I would like this to print "I am an instance of B" but I keep getting A. Can someone help me out here.
Why would creating an alias for class B execute the initializer for
perhaps you meant:
x = B()
BTW, since you're on 2.x python, you should derive A from object.
Otherwise it's an old-style class.
More information about the Python-list