Python Learning Module & package reference, python Module
Glossary:
Module: A program file
Package: it is equivalent to a class library. After packaging and publishing, it is equivalent to a dll in c #. The package may contain several modules. For example, main. py is a module, which makes up a package for all modules in the test2 file.
For a package, it is destined to be referenced by other modules. Therefore, an initialization information, such as the package path, is required, these information is dependent on the _ init _ py file under the package. For the sub-packages under the package (sub-namespaces under the namespace), the _ init _ py file exists at each level.
For details, refer
The following describes how to reference a module or package in the code.
1: reference the provide. py module in the main program main. py and execute the Method
Import provide;
Provide. stringProvider ("hello ");
Or
From provide import stringProvider;
StringProvider ("hello ");
Or
From provide import stringProvider;
A = stringProvider;
A ("hello ");
2: reference the module under the test2 class library in the main program main. py and execute the Method
We want to access the info. py module method in tester under test2. Because the class library and module are not in the same directory, we must add an upper-layer path.
There are many ways to access different directories, you can refer to http://python.usyiyi.cn/python_343/tutorial/modules.html#packages-in-multiple-directories
The code is
Import sys;
Sys. path. append ("..");
Therefore, you can reference the data in the same way as above.
From test2.tester import info;
Info. printinfo ();
If it is written as import test2.tester.info;
The reference of the method must also be complete: test2.tester.info. printinfo ();