Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: derived class name in python 2.6/2.7 (http://www.velocityreviews.com/forums/t957103-re-derived-class-name-in-python-2-6-2-7-a.html)

Oscar Benjamin 01-30-2013 08:17 PM

Re: derived class name in python 2.6/2.7
 
On 30 January 2013 20:05, Sells, Fred <fred.sells@adventistcare.org> 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


Did you mean to use __name__ instead of name?

>
> class B(A):
> pass
>
> X = B


I assume that this is
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.


If you make those two changes then it should do what you want.


Oscar


All times are GMT. The time now is 11:03 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.