Creating a __main__ module
To work with the runpy interface, we must add a small __main__.py module to our application's top-level package. We have emphasized the design of this top-level executable script file.
We should always permit refactoring an application to build a larger, more sophisticated composite application. If there's functionality buried in __main__.py, we need to pull this into a module with a clear, importable name so that it can be used by other applications.
A __main__.py module follows the kind of code shown in the previous section, Creating an executable script file. The only real distinction is using the special name, __main__.py, to make it easier for the Python runtime to locate the main module of a package. It also ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access