Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: derived class name in python 2.6/2.7

Reply
Thread Tools

Re: derived class name in python 2.6/2.7

 
 
Oscar Benjamin
Guest
Posts: n/a
 
      01-30-2013
On 30 January 2013 20:05, Sells, Fred <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
derived class name in python 2.6/2.7 Sells, Fred Python 0 01-30-2013 08:05 PM
Derived Structure in Derived Class?? David C++ 3 01-29-2008 07:38 AM
Retrieving derived class name inside base class Goran Djuranovic ASP .Net 8 09-17-2007 04:58 PM
Derived::Derived(const Base&) and Derived& operator=(const Base&) developereo@hotmail.com C++ 1 05-23-2007 01:44 PM
Derived::Derived(const Base&) and Derived& operator=(const Base&) developereo@hotmail.com C++ 1 05-23-2007 12:07 AM



Advertisments