An identifier occurring as an atom is a name. See section 4.1 for documentation of naming and binding.
作为一个原子出现的标识符是对一个局部名字, 或全局名字或内建名字捆绑的引用. 如果该名字出现在某代码块的任意的一个地方(即使是在不可达的代码中), 而且它未在global语句中的话, 那么它就是该代码块的局部名字. 当它没在代码块被赋值,或者虽然被赋值但是它是在globals语句中显式地列出的话, 它就是引用的一个全局名字(如果它存在), 或者一个内建名字(这个捆绑规则可以动态改变).5.1
When the name is bound to an object, evaluation of the atom yields that object. When a name is not bound, an attempt to evaluate it raises a NameError exception.
当某名字捆绑的是一个对象时, 使用该原子就是使用那个对象. 当某名字没有捆绑就直接使用它, 则会抛出一个NameError异常.
私有名字变换: Private name mangling:
When an identifier that textually occurs in a class definition begins
with two or more underscore characters and does not end in two or more
underscores, it is considered a private name of that class.
Private names are transformed to a longer form before code is
generated for them. The transformation inserts the class name in
front of the name, with leading underscores removed, and a single
underscore inserted in front of the class name. For example, the
identifier __spam
occurring in a class named Ham
will be
transformed to _Ham__spam
. This transformation is independent
of the syntactical context in which the identifier is used. If the
transformed name is extremely long (longer than 255 characters),
implementation defined truncation may happen. If the class name
consists only of underscores, no transformation is done.
在类定义中, 以两个或多个下划线开始, 并且尾部不是以两个或多个下划线结束的标识符, 它被看作是类的私有名字. 在产生它的代码之前, 私有名字被变换成更长的形式. 这种变换是在将去掉前导下划线的类名插入到名字前,再在类名前插入一个下划线。 .例如, 在类Ham中定义的标识符__spam, 会被变换成_Ham__spam. 本变换是不依赖于使用该标识符处代码的句法上的上下文的. 如果变换后的结果过长(超过255个字符), 就会执行该Python实现定义的截短名字的操作. 如果某类的名字仅仅由下划线组成, 这种变换是不会发生的.