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. Advertisements

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. E11
    Replies:
    1
    Views:
    5,755
    Thomas Weidenfeller
    Oct 12, 2005
  2. Devrim Erdem
    Replies:
    1
    Views:
    438
    John J. Lee
    Jan 17, 2004
  3. Replies:
    11
    Views:
    602
    Steven Bethard
    Nov 16, 2005
  4. Jordan Taylor

    name lookup in derived class

    Jordan Taylor, Mar 1, 2006, in forum: C++
    Replies:
    3
    Views:
    310
    Neelesh Bodas
    Mar 1, 2006
  5. Replies:
    1
    Views:
    636
    myork
    May 23, 2007
  6. Replies:
    1
    Views:
    541
    Victor Bazarov
    May 23, 2007
  7. Goran Djuranovic

    Retrieving derived class name inside base class

    Goran Djuranovic, Sep 10, 2007, in forum: ASP .Net
    Replies:
    8
    Views:
    606
    Goran Djuranovic
    Sep 17, 2007
  8. David
    Replies:
    3
    Views:
    606
    Grizlyk
    Jan 29, 2008
Loading...