Bag

Package, in fact, in some of the above examples, different package names have been created. You can observe the details carefully. As mentioned in the introduction to modules at the beginning, using modules can avoid conflicts between function names and variable names. Functions and variables with the same name can exist in different modules. Therefore, when we write the module ourselves, we do not have to consider that the name will conflict with other modules. But also be careful not to conflict with built-in function names. But there is also a problem here. What if the module names written by different people are the same? In order to avoid module name conflicts, Python has introduced a method of organizing modules by directory, called a package.

For example, in the initial example, packages are introduced. In this way, even if there are the same module names, there will be no duplication, because different package names actually mean different paths. As shown below, after the package name is introduced, lname.py actually becomes com.Learn.module.nameattributes.lname

512cbe33776897185188520cffb49e4.png

People who observe carefully will basically find that every There will be an __init__.py file under a package directory. Why?

Because this file is required, otherwise, Python will treat this directory as an ordinary directory, not a package. __init__.py can be an empty file, or it can have Python code, because __init__.py itself is a module, and its corresponding module name is its package name.


Continuing Learning
||
submitReset Code