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


Groups > comp.lang.python > #76641 > unrolled thread

Re: what is the difference between name and _name?

Started byBen Finney <ben+python@benfinney.id.au>
First post2014-08-20 17:28 +1000
Last post2014-08-20 17:28 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: what is the difference between name and _name? Ben Finney <ben+python@benfinney.id.au> - 2014-08-20 17:28 +1000

#76641 — Re: what is the difference between name and _name?

FromBen Finney <ben+python@benfinney.id.au>
Date2014-08-20 17:28 +1000
SubjectRe: what is the difference between name and _name?
Message-ID<mailman.13191.1408519721.18130.python-list@python.org>
luofeiyu <elearn2014@gmail.com> 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
<URL:https://docs.python.org/3/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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web