From 1a8d57e6d2b359fe91c6551a90ade4f8a9314d65 Mon Sep 17 00:00:00 2001 From: Andrey Doroschenko Date: Thu, 27 Feb 2020 14:38:13 +0300 Subject: [PATCH] bpo-39774: docs how to make package executable --- Doc/tutorial/modules.rst | 19 ++++++++++++++++++- .../2020-02-27-14-37-48.bpo-39774.K8tQe4.rst | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Documentation/2020-02-27-14-37-48.bpo-39774.K8tQe4.rst diff --git a/Doc/tutorial/modules.rst b/Doc/tutorial/modules.rst index af595e5ca04..6c529d9a342 100644 --- a/Doc/tutorial/modules.rst +++ b/Doc/tutorial/modules.rst @@ -476,6 +476,23 @@ except for the last must be a package; the last item can be a module or a package but can't be a class or function or variable defined in the previous item. +If you want to make your package executable you need to create :file:`__main__.py`. + +.. code-block:: text + + sound/ + __init__.py + __main__.py Executable package + formats/ + effects/ + filters/ + +Then you can run your package as the executable: + +.. code-block:: shell-session + + $ python -m sound + .. _tut-pkg-import-star: @@ -552,7 +569,7 @@ module for example, you might use:: from ..filters import equalizer Note that relative imports are based on the name of the current module. Since -the name of the main module is always ``"__main__"``, modules intended for use +the name of the main module is always ``__main__``, modules intended for use as the main module of a Python application must always use absolute imports. diff --git a/Misc/NEWS.d/next/Documentation/2020-02-27-14-37-48.bpo-39774.K8tQe4.rst b/Misc/NEWS.d/next/Documentation/2020-02-27-14-37-48.bpo-39774.K8tQe4.rst new file mode 100644 index 00000000000..9e9ee72ce8b --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2020-02-27-14-37-48.bpo-39774.K8tQe4.rst @@ -0,0 +1 @@ +Added documentation on how to make package executable as script