sys.path.append
时间: 2023-12-26 16:01:29 浏览: 39
(sys.path.append) is a Python function that adds a path to the list of locations where Python looks for modules to import.
When Python tries to import a module, it first looks in its built-in modules, then in the current directory, and then in the list of directories specified in the sys.path variable. By appending a new path to this list, you can add your own modules or packages that are located in a different directory.
For example, if you have a module named "my_module" in the directory "/home/user/my_project", you can add this directory to the sys.path list using the following code:
import sys
sys.path.append('/home/user/my_project')
Now, when you try to import "my_module", Python will look in the "/home/user/my_project" directory and find the module.