Python Basics Module
A module is a file that contains the Python definition and declaration, and the filename is the suffix of the module name plus the. Py.
is a python file that defines classes and methods, implements functions that can be called by other Python files
So how do you use a module?
Of course, using the Import module name this way to load a module, such as: Import time
If you want to use a class in a module, it is:
Module name, such as: Import Modle. Teacher
So what if the method in the module doesn't know what to do with it?
Two methods:
1.help (module name. Class)
2.Ctrl + Left button click Class
So how do you make a call module across directories?
Hierarchical structure:
Dir1
---hello.py
Dir2
---main.py
Among them, hello.py:
def add (x, y):
Return X+y
How main.py can be called to the Add function in hello.py.
This is still very simple:
Import sys sys.path.append ("D:/dir1") #添加你要导入的模块的路径, note: The path to run is based on the file you executed!!! Import Hello print (hello.add)
Python Basics Module