Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #37961 > unrolled thread

Re: derived class name in python 2.6/2.7

Started byDave Angel <d@davea.name>
First post2013-01-30 15:20 -0500
Last post2013-01-30 15:20 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: derived class name in python 2.6/2.7 Dave Angel <d@davea.name> - 2013-01-30 15:20 -0500

#37961 — Re: derived class name in python 2.6/2.7

FromDave Angel <d@davea.name>
Date2013-01-30 15:20 -0500
SubjectRe: derived class name in python 2.6/2.7
Message-ID<mailman.1229.1359577261.2939.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web