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


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

Re: derived class name in python 2.6/2.7

Started byOscar Benjamin <oscar.j.benjamin@gmail.com>
First post2013-01-30 20:17 +0000
Last post2013-01-30 20:17 +0000
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 Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-01-30 20:17 +0000

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

FromOscar Benjamin <oscar.j.benjamin@gmail.com>
Date2013-01-30 20:17 +0000
SubjectRe: derived class name in python 2.6/2.7
Message-ID<mailman.1228.1359577028.2939.python-list@python.org>
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

[toc] | [standalone]


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


csiph-web