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

 
 
Dave Angel
Guest
Posts: n/a
 
      01-30-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):
> 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.
>


Why would creating an alias for class B execute the initializer for
either class?

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.

--
DaveA
 
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