Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #30094

Re: data attributes override method attributes?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!hq-usenetpeers.eweka.nl!81.171.88.250.MISMATCH!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; '"""': 0.05; 'attribute': 0.05; 'assign': 0.07; 'attributes': 0.07; 'class,': 0.07; 'correct.': 0.07; 'override': 0.07; 'python': 0.09; 'correct,': 0.09; 'precedence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sep': 0.09; 'subject:method': 0.09; 'bug': 0.10; 'accidental': 0.16; 'attributes,': 0.16; 'attributes.': 0.16; 'definition.': 0.16; 'name"': 0.16; 'namespace.': 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; 'url:py3k': 0.16; 'string': 0.17; 'wrote:': 0.17; 'instance': 0.17; 'replacing': 0.17; 'url:dev': 0.17; 'saying': 0.18; 'assignment': 0.22; 'bug?': 0.22; 'name;': 0.22; 'defined': 0.22; 'demonstrate': 0.23; 'url:bugs': 0.24; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'bugs': 0.27; 'right.': 0.27; 'convention': 0.27; 'replace': 0.27; 'header:X-Complaints-To:1': 0.28; 'all.': 0.28; '(perhaps': 0.29; 'behaviour': 0.29; 'implies': 0.29; 'no,': 0.29; 'class': 0.29; 'usually': 0.30; 'url:python': 0.32; 'file': 0.32; 'conventions': 0.33; 'subject:data': 0.33; 'to:addr:python- list': 0.33; 'tutorial': 0.33; 'wrong': 0.34; 'subject:?': 0.35; 'something': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; "didn't": 0.36; 'method': 0.36; 'should': 0.36; 'possible': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'your': 0.60; 'share': 0.61; 'chance': 0.61; 'kind': 0.61; 'therefore': 0.65; '26,': 0.65; 'programs,': 0.71; 'capitalizing': 0.84; 'otten': 0.84; 'conflicts,': 0.91; 'url:tutorial': 0.93
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:54:12 +0200
Organization None
References <931902e1-570b-4288-bb9b-de711318c5cd@googlegroups.com> <mailman.1338.1348582105.27098.python-list@python.org> <c3fb0a89-abb9-4107-89cd-3f4ee17b40e1@t2g2000pbt.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p5084a6c1.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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1341.1348584870.27098.python-list@python.org> (permalink)
Lines 58
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1348584870 news.xs4all.nl 6854 [2001:888:2000:d::a6]:43367
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:30094

Show key headers only | View raw


alex23 wrote:

> On Sep 26, 12:08 am, Peter Otten <__pete...@web.de> wrote:
>> 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.
> 
> But you can assign attributes on the class, which has the same impact,
> so the tutorial is correct.
> 
>> No, you're right. Please file a bug report athttp://bugs.python.org
> 
> Didn't you just demonstrate the behaviour you're now saying is a bug?
> 

To me

"Data attributes override method attributes with the same name"

implies that data attributes take precedence over method attributes, not 
that they replace them only when there is an assignment of data after the 
method definition. 

With your interpretation (if I understand you correctly)

"Method attributes override data attributes with the same name"

is equally correct, and therefore I think it is misleading to focus on the 
type of the attributes at all. 

I would even consider replacing the whole paragraph

"""
Data attributes override method attributes with the same name; to avoid 
accidental name conflicts, which may cause hard-to-find bugs in large 
programs, it is wise to use some kind of convention that minimizes the 
chance of conflicts. Possible conventions include capitalizing method names, 
prefixing data attribute names with a small unique string (perhaps just an 
underscore), or using verbs for methods and nouns for data attributes.
"""
http://docs.python.org/dev/py3k/tutorial/classes.html

with something like

"Data attributes and method attributes share the same namespace. To avoid 
name conflicts consider using verbs for methods and nouns for data 
attributes"

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

data attributes override method attributes? Jayden <jayden.shui@gmail.com> - 2012-09-25 06:41 -0700
  Re: data attributes override method attributes? alex23 <wuwei23@gmail.com> - 2012-09-25 06:52 -0700
  Re: data attributes override method attributes? Peter Otten <__peter__@web.de> - 2012-09-25 16:08 +0200
    Re: data attributes override method attributes? alex23 <wuwei23@gmail.com> - 2012-09-25 07:11 -0700
      Re: data attributes override method attributes? Peter Otten <__peter__@web.de> - 2012-09-25 16:54 +0200
      Re: data attributes override method attributes? Chris Angelico <rosuav@gmail.com> - 2012-09-26 01:03 +1000
      Re: data attributes override method attributes? Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-09-25 16:54 +0200
      Re: data attributes override method attributes? Terry Reedy <tjreedy@udel.edu> - 2012-09-25 15:58 -0400
      Re: data attributes override method attributes? Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-25 14:07 -0600
      Re: data attributes override method attributes? Terry Reedy <tjreedy@udel.edu> - 2012-09-25 16:18 -0400
      Re: data attributes override method attributes? Terry Reedy <tjreedy@udel.edu> - 2012-09-25 16:34 -0400
      RE: data attributes override method attributes? "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-09-28 18:02 +0000
        Re: data attributes override method attributes? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-29 03:20 +0000
      Re: data attributes override method attributes? Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-28 12:25 -0600
      Re: data attributes override method attributes? Terry Reedy <tjreedy@udel.edu> - 2012-09-28 14:26 -0400
    Re: data attributes override method attributes? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-09-25 21:52 +0200
  Re: data attributes override method attributes? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-25 14:12 +0000

csiph-web