Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'explicitly': 0.05; 'attribute': 0.07; 'class,': 0.07; 'result,': 0.07; 'attributes': 0.09; 'python': 0.11; 'def': 0.12; '"a"': 0.16; '23,': 0.16; '7:35': 0.16; 'a(object):': 0.16; 'adam': 0.16; 'arg):': 0.16; 'called.': 0.16; 'condensed': 0.16; 'overridden': 0.16; 'subject:object': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'print': 0.22; '(such': 0.24; "haven't": 0.24; 'question': 0.24; 'class.': 0.26; 'defined': 0.27; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'generally': 0.29; 'message- id:@mail.gmail.com': 0.30; 'directly,': 0.31; 'raised': 0.31; 'class': 0.32; 'another': 0.32; 'cases': 0.33; 'skip:_ 10': 0.34; 'subject:the': 0.34; 'received:google.com': 0.35; 'method': 0.36; 'example,': 0.37; 'handle': 0.38; 'needed': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; "you're": 0.61; 'name': 0.63; 'field': 0.63; 'refer': 0.63; 'here': 0.66; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=0bna0dfvisfaBmRQ10d3l87VzEIoFe8Fn6nG5JDZwqw=; b=k6JoCJLtl2xx0MPt6PfLaMGOCX/BGkJWqCfL8q1QFLxspFmV4mpS5g9C5kW+noLA7X 6ERI0HEKfSaF0b4JbsGsyJVvRGQjV9ksSe9jm1CIi21kCPll1O9rqV4ivljCM8/VUHjY UlXeOn1p66niMwyoFy3Y9dmTMriqPJiv3I413Ot+iSNH+TUsweVYYBqY/62VknmMb8Y3 sSDcDc2w1HM04G06CJS67gxifyRgHF92bSs1prn+CIamM000zb9rkzq0qwY+sykZC4uf GArlEDPeIQtaGXx8I89lgKosC4MWvhrDNjEIH1cmSAM4h04IlXwsItDT1Q1vXU5bwf0T oTgw== X-Received: by 10.68.224.161 with SMTP id rd1mr20337401pbc.121.1372004178874; Sun, 23 Jun 2013 09:16:18 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20130623133546.GA2308@capricorn> References: <15ba0011-bbf1-42f7-b3ea-1c1d4b70e56b@googlegroups.com> <51c66962$0$29999$c3e8da3$5496439d@news.astraweb.com> <20130623133546.GA2308@capricorn> From: Ian Kelly Date: Sun, 23 Jun 2013 10:15:38 -0600 Subject: Re: What is the semantics meaning of 'object'? To: Python Content-Type: text/plain; charset=ISO-8859-1 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372004188 news.xs4all.nl 15891 [2001:888:2000:d::a6]:35387 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48988 On Sun, Jun 23, 2013 at 7:35 AM, Adam Jiang wrote: > Another question raised here is that what is the proper way to refer > to parent class? For example, > > class A(object): > def __init__(self, arg): > print "A" > > class B(A): > def __init__(self, arg): > super(B, self).__init__(arg) > > Is this correct? As the result, whenever you wanted to refer to a > method in parent class, super() functions has to be called. This seems > inefficient. Generally, use super() any time you want to refer to a class attribute (such as a method) in a parent class that is overridden in the child class. Also note that in Python 3, the call "super(B, self)" can be condensed to just "super()". If you're worried about efficiency, you can also explicitly name the superclass in order to call the method directly, like: A.__init__(self, arg) However, super() is generally considered the right way to do this, in order to avoid repeating the parent class name, for brevity in Python 3, and because it is needed to correctly handle some cases of multiple inheritance. > How to refer to a field defined in parent class? For instance attributes or attributes that haven't been overridden, just write "self.attribute_name".