1.Definition
Module: The essence is a file ending in .py (logically organizing python code). The essence of a module is to implement a function. The file name is the module name
Package: A folder with __init__.py; used to store module files
2. Import module
import module name
form module name import *
from module name import module name as new name
3. Import module essence
import module name ===》 Assign all data in the module to the module name. The module name.method name () is required when calling.
from module name import method name ==》Put this method into the current file and run it once. When calling, you only need the method name () to run it
Importing a package is to execute the __init__.py file under the package
Path search
import sys,os
os.path.abspath(__file__) #Get the full name of the current file
os.path.dirname() #Get the parent directory of the current object
sys.path.insert()#Add the path of the current object to the first place
sys.path.append() # Add the current environment variable to the end of the environment variable
The above is the detailed content of Python Day05 python environment variables and import module import. For more information, please follow other related articles on the PHP Chinese website!