Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '__name__': 0.07; 'subject:2.7': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'subject:python': 0.11; 'assume': 0.11; 'b()': 0.16; 'subject:class': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'changes': 0.20; 'bit': 0.21; 'cc:2**0': 0.23; 'to:2**1': 0.23; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'subject:/': 0.28; 'name?': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; 'basic': 0.30; 'print': 0.32; 'getting': 0.33; 'received:google.com': 0.34; 'but': 0.36; 'should': 0.36; 'two': 0.37; 'quite': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'instead': 0.39; 'help': 0.40; '2013': 0.84; 'oscar': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=NsRL014Q0Z6kqxzj+ddxQv1l+iU11lEUXrcqetYiTNk=; b=Rn9NXoZ50ObtlR42cCfo/jmqyA/4ABaAGwKwqqfVkjdszos48trgNlhx+1i4p667aF qgNZT4PAJFTTeqgom5Pgisj2t8pejecBJe+x4KyuTMJL5FDVHaj7mk9FOv4rlHdlhank MudATLRfukAvXzYYel8XERNEVgEdIQPM04bkoBT80DoueE6xb5pHHJ5CvZVAqNJNO6nL mTa3gASQNck59pxe1cK+vvEF9Dva3+WF+zQwLBDwh/e4PlrdB2Xjnh2FhttEpjPYE1Pd 2oO/Os8uNTf9pAAYU9t8egaU+cv3dZCYYfNL6iv0b8915gCt6mW7pCauHv9fwwmj5bRW g+vg== MIME-Version: 1.0 X-Received: by 10.152.144.71 with SMTP id sk7mr5694745lab.29.1359577025882; Wed, 30 Jan 2013 12:17:05 -0800 (PST) In-Reply-To: References: Date: Wed, 30 Jan 2013 20:17:05 +0000 Subject: Re: derived class name in python 2.6/2.7 From: Oscar Benjamin To: "Sells, Fred" Content-Type: text/plain; charset=ISO-8859-1 Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359577028 news.xs4all.nl 6987 [2001:888:2000:d::a6]:39646 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37960 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