derived class name in python 2.6/2.7

Discussion in 'Python' started by Sells, Fred, Jan 30, 2013.

  1. Sells, Fred

    Sells, Fred Guest

    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.
    Sells, Fred, 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:
    387
    myork
    May 23, 2007
  2. Replies:
    1
    Views:
    374
    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:
    430
    Goran Djuranovic
    Sep 17, 2007
  4. David
    Replies:
    3
    Views:
    391
    Grizlyk
    Jan 29, 2008
  5. Oscar Benjamin

    Re: derived class name in python 2.6/2.7

    Oscar Benjamin, Jan 30, 2013, in forum: Python
    Replies:
    0
    Views:
    127
    Oscar Benjamin
    Jan 30, 2013
Loading...

Share This Page