Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'tutorial': 0.03; 'api.': 0.05; 'attribute': 0.07; 'class,': 0.07; 'only,': 0.07; 'attributes': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'api': 0.11; 'python': 0.11; 'api,': 0.16; 'finney': 0.16; 'grasp': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:between': 0.16; 'underscore.': 0.16; 'header:User- Agent:1': 0.23; 'module,': 0.24; 'supported': 0.26; 'header:X -Complaints-To:1': 0.27; 'designer': 0.30; "i'm": 0.30; 'etc.).': 0.31; 'object.': 0.31; 'subject:what': 0.31; 'them?': 0.31; 'time;': 0.31; 'writes:': 0.31; 'covered': 0.32; 'url:python': 0.33; 'beginning': 0.33; 'skip:_ 10': 0.34; 'subject:the': 0.34; 'but': 0.35; 'useful': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'should': 0.36; 'so,': 0.37; 'ben': 0.38; 'convention': 0.38; 'to:addr:python-list': 0.38; 'itself': 0.39; 'use.': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'completed': 0.61; 'url:3': 0.61; 'name': 0.63; 'details': 0.65; 'effectively': 0.66; 'between': 0.67; 'close': 0.67; 'promise': 0.68; 'wear': 0.68; 'basics.': 0.84; 'brain,': 0.84; 'received:125': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: what is the difference between name and _name? Date: Wed, 20 Aug 2014 17:28:23 +1000 References: <53F44B68.7010903@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:eY7qKa/JQfCUAcWRJOWhxg7m+0I= 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408519721 news.xs4all.nl 2875 [2001:888:2000:d::a6]:43137 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76641 luofeiyu writes: > When i learn property in python , i was confused by somename and > _somename,what is the difference between them? Some attributes are exposed in the API for an object (a class, a module, etc.). Those are effectively a promise from the author that the attribute is supported for use. A name like ‘foo’ is part of the API. Other attributes are details of the implementation only, and are designed to be used only by the object itself or its close collaborators. Those attributes which are not published, are not part of the API, are details of the implementation. Depending on them to remain useful is an error, since they can change at any time; they are not part of the promise made by the designer of the object. The convention on Python is to name implementation-detail attributes with a single leading underscore. A name like ‘_foo’ is not part of the API and using it from the outside is a mistake. You should already have completed the Python tutorial by now. This conventionis covered there; you should work through the tutorial from beginning to end in order to get a good grasp of Python basics. -- \ “Are you pondering what I'm pondering?” “Umm, I think so, | `\ Brain, but what if the chicken won't wear the nylons?” —_Pinky | _o__) and The Brain_ | Ben Finney