Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'alias': 0.07; 'subject:2.7': 0.09; 'def': 0.10; 'subject:python': 0.11; 'b()': 0.16; 'old-style': 0.16; 'subject:class': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'bit': 0.21; '2.x': 0.22; 'object.': 0.22; 'class.': 0.23; 'pass': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'creating': 0.26; 'subject:/': 0.28; 'skip:_ 10': 0.29; 'class': 0.29; 'basic': 0.30; 'print': 0.32; 'getting': 0.33; 'to:addr:python-list': 0.33; 'pm,': 0.35; 'but': 0.36; 'should': 0.36; 'execute': 0.37; 'why': 0.37; 'quite': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'help': 0.40; 'received:74.208': 0.71 Date: Wed, 30 Jan 2013 15:20:33 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: derived class name in python 2.6/2.7 References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:NBBl7R7tSydtduOGS6Wk+gcPj52tsfbAVUnTMzEp+ny /tDFGLM0OjsgUIHC7lS3vTT8ElKzI8G6ldO4Oq3xSoBecH9Dtn beS/FqD+BajUTg4cFMgV5UD+QlBf1bROU9BkxgIYSvJc+KX02O Z8CMIQxFqFmZdV7RYwlkc+NrIsI8oJTxm8ylDFTzoW9SDjkEu5 5vQamWWdpZGdBK2aBu8LMiIA/2DlSHJ2dmh2uNiGFAdC5sP1p5 fok2r9TPxvIsO3yVhzUAhJwXXHgADlfzBpr0bRY8E3E0RZshEl FjVxAvnEtWMlj6cMB2cbw9ilPrZ5MOLAu3+gqfoaBdTD3cO5A= = 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359577261 news.xs4all.nl 6867 [2001:888:2000:d::a6]:42103 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37961 On 01/30/2013 03:05 PM, 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 > > 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. > Why would creating an alias for class B execute the initializer for either class? perhaps you meant: x = B() BTW, since you're on 2.x python, you should derive A from object. Otherwise it's an old-style class. -- DaveA