Re: derived class name in python 2.6/2.7

Discussion in 'Python' started by Oscar Benjamin, Jan 30, 2013.

  1. On 30 January 2013 20:05, 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


    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
    Oscar Benjamin, Jan 30, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    383
    myork
    May 23, 2007
  2. Replies:
    1
    Views:
    371
    Victor Bazarov
    May 23, 2007
  3. Goran Djuranovic

    Retrieving derived class name inside base class

    Goran Djuranovic, Sep 10, 2007, in forum: ASP .Net
    Replies:
    8
    Views:
    429
    Goran Djuranovic
    Sep 17, 2007
  4. David
    Replies:
    3
    Views:
    386
    Grizlyk
    Jan 29, 2008
  5. Sells, Fred

    derived class name in python 2.6/2.7

    Sells, Fred, Jan 30, 2013, in forum: Python
    Replies:
    0
    Views:
    126
    Sells, Fred
    Jan 30, 2013
Loading...

Share This Page