Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

derived class name in python 2.6/2.7

 
 
Sells, Fred
Guest
Posts: n/a
 
      01-30-2013
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):
pass


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.

 
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
Re: derived class name in python 2.6/2.7 Oscar Benjamin Python 0 01-30-2013 08:17 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