Reference One, Package
A package is a folder that is used to store modules and sub-packages.
There is usually a __init__.py file (or no) in the package.
There will be a __pycache__ folder in the package that holds the intermediate bytecode (binary files) that the. py file is interpreted by the interpreter.
Second, the module
Files that can be used as modules have . py,. PYc,. Pyo,. PYD,. So,.dll files.
Iii.. pyc files with the. pyo file
These two files are binary files, and the Python interpreter transforms the. py file into a binary file that is designed to speed up interpretation and hide the source code.
When the Python interpreter interprets the. py file, it takes precedence over whether the latest. pyc file is available, or the. pyc file is loaded directly. Before loading, the. pyc file is checked for the latest (determine the modified time for the. py file), and if it is not up-to-date, the. py file is interpreted.
The. pyc file can be generated by Python's own module Py_compile, and a __pycache__ folder is automatically generated to hold the. pyc file.
If you do not have a. py file, only the corresponding. pyc file can also be called because the. pyc file can be used as a module.
The. pyo file is an optimized version of the. pyc file for the same purpose.
Iv. Role of __init__.py documents
The __init__.py function is to turn the package into a module (using a module like. py)
If there is a package name:
1. Add the __all__=[' OS ', ' sys ', ' base64 '] variables in the file, and the variables contain the module names that need to be used. This allows the modules in the __DATA__ list to be loaded in from the package import *.
2. Add the import OS to the file, import the packages that need to be imported so that the package can be called through the pack. OS (must add the package name).
How to put the module you wrote into the package import path
Import Sys
Sys.path.append (' Your path ')
Typically place a package or module in the current directory of the startup file
About Python packages, modules,. pyc files and file import understanding