One problem from. Import of

Absolute Import: start looking for (first element is the currently executing program directory) from the list sys.path module search path

Relative imports: start looking for the file from import statement resides on behalf of the current directory where the file directory, on behalf of the current directory .. the parent directory files

ps: __name__ relative path depends on variables introduced, according to its value to find the same level or a higher level directory or file,

After the module is imported, python interpreter creates a variable named __name__ for the module, and the module where the absolute path for this variable is stored in the directory,

The .py file is run, python for the program will create a variable named __name__, and assigned to the string "__main__", so the currently executing program can not use relative imports,

from. import name will prompt an error can not import name 'name'

from .. import name will prompt an error attempted relative import beyond top-level package

 

Guess you like

Origin www.cnblogs.com/Clownly/p/11515402.html