Path: csiph.com!usenet.pasdenom.info!news.albasani.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'method.': 0.05; 'attributes': 0.07; 'override': 0.07; 'python': 0.09; 'callable': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:method': 0.09; 'typeerror:': 0.09; 'bug': 0.10; 'def': 0.10; "'int'": 0.16; 'a()': 0.16; 'attributes.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'wrote:': 0.17; 'instance': 0.17; '>>>': 0.18; '"",': 0.22; 'assignment': 0.22; 'defined': 0.22; 'url:bugs': 0.24; 'testing': 0.24; 'header:User-Agent:1': 0.26; '(most': 0.27; 'right.': 0.27; 'header:X-Complaints-To:1': 0.28; 'no,': 0.29; 'objects': 0.29; 'class': 0.29; 'usually': 0.30; 'url:python': 0.32; 'file': 0.32; 'could': 0.32; 'print': 0.32; 'subject:data': 0.33; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'tutorial': 0.33; 'wrong': 0.34; 'follows:': 0.35; 'subject:?': 0.35; 'something': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'method': 0.36; 'should': 0.36; 'author': 0.37; 'two': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'mind:': 0.84; 'why?': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: data attributes override method attributes? Date: Tue, 25 Sep 2012 16:08:08 +0200 Organization: None References: <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084a81a.dip.t-dialin.net User-Agent: KNode/4.7.3 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: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348582105 news.xs4all.nl 6963 [2001:888:2000:d::a6]:36463 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30086 Jayden wrote: > In the Python Tutorial, Section 9.4, it is said that > > "Data attributes override method attributes with the same name." The tutorial is wrong here. That should be "Instance attributes override class attributes with the same name." As methods are usually defined in the class and data attributes are usually set in the instance it will look like data override method attributes. What the author had in mind: >>> class A: ... def i(self): print "method" ... >>> >>> a = A() >>> a.i() method >>> a.i = 42 # this could also happen in a method with self.i = 42 >>> a.i() Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not callable >>> a.i 42 > But in my testing as follows: > > #Begin > class A: > i = 10 > def i(): > print 'i' > > A.i > > #End but class A: def i(self): print "i" i = 42 print A().i # 42 If two objects are assigned to the same name the last assignment always wins. > I think A.i should be the number 10 but it is the method. There must be something I misunderstand. Would you please tell me why? No, you're right. Please file a bug report at http://bugs.python.org