擅长:python、mysql、java
<p>虽然没有显式的私有关键字,但是有一个约定是将私有函数以一个下划线开头,但是一个双前导下划线将使其成为这样,其他人就不能从模块外部轻松调用该函数。请参阅<a href="http://www.python.org/dev/peps/pep-0008/" rel="noreferrer">PEP 8</a>中的以下内容</p>
<pre><code>- _single_leading_underscore: weak "internal use" indicator. E.g. "from M
import *" does not import objects whose name starts with an underscore.
- single_trailing_underscore_: used by convention to avoid conflicts with
Python keyword, e.g.
Tkinter.Toplevel(master, class_='ClassName')
- __double_leading_underscore: when naming a class attribute, invokes name
mangling (inside class FooBar, __boo becomes _FooBar__boo; see below).
- __double_leading_and_trailing_underscore__: "magic" objects or
attributes that live in user-controlled namespaces. E.g. __init__,
__import__ or __file__. Never invent such names; only use them
as documented.
</code></pre>
<p>要使整个模块成为私有模块,请不要包含它<code>__init__.py</code>文件。</p>