明示的なプライベート キーワードはありませんが、プライベート関数を 1 つのアンダースコアで開始するという規則がありますが、先頭に 2 つのアンダースコアを付けると、他の人がモジュールの外部から関数を簡単に呼び出すことができなくなります。PEP 8から以下を参照してください
- _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.
__init__.py
モジュール全体を非公開にするには、そのファイル をインクルードしないでください。