1. Relationship among lib, package and module in Python
.pyFiles ending with are modules.
package: it’s a belt
__init__.pyFolder * * (must have!!!) * * and others
.pyDocument composition, where
__init__.pyIt can be an empty file or it can contain Python code.
lib: in Python, modules and packages with certain functions can be called libraries, which can containPackages, modules, and functions。
2. Reference custom module
2.0 document structure
2.1 module1 module in test1 package
class T1(object): def __init__(self): super().__init__() def func1(self): print('ok1')
2.2 module2 module in test2 package
class T2(object): def __init__(self): super().__init__() def func2(self): print('ok2')
2.3 test module in test2 package
###Reference modules in the same folder import sys Sys.path.append (root directory)# from testpackage.test2.module2 import T2 T2 (). Func2 () # output ok2 ####Reference modules in different folders from testpackage.test1.module1 import T1 T1 (). Func1 () # output OK1
As shown in the figure, when the module reference is notProblemss warning, and the program can run normally.
But when we added it to the root directory
\\testpackageThen it appearedProblemss warns that this does not affect the normal operation of the program.
summary: when referencing a custom module, you need to add the root directory before referencing. If you add the custom file directory to the root directory at the same time, as shown in the above figureTestpackage, the compiler will report an error, but it will not affect the normal operation of the program.
The customized file directory is added to the root directory at the same time, as shown in the above figureTestpackage, the compiler will report an error, but it will not affect the normal operation of the program.
This is the end of this article on referencing custom modules in vscode. For more information about vscode referencing custom modules, please search for previous articles of developeppaer or continue to browse the relevant articles below. I hope you will support developeppaer in the future!