Absolute Imports in Python

preview_player
Показать описание
An absolute import specifies the resource to be imported using its full path from the project’s root folder. Absolute imports are preferred because they are quite clear and straightforward. It is easy to tell exactly where the imported resource is, just by looking at the statement.

In addition, absolute imports remain valid even if the current location of the import statement changes. In fact, PEP 8 explicitly recommends absolute imports. Sometimes, however, absolute imports can get quite verbose, depending on the complexity of the directory structure.

Рекомендации по теме
Комментарии
Автор

Where is the next video about relative imports?

Norfeldt
Автор

Hello im newbie on python. i want ask my problem.
how about if i in module2.py and i put code from projects.package2.module3 import function and execute module2.py there is a error, cannot find module "projects"

if i use relative path like from ...package2.module3 import function
there is error cannot find parent relative path bla bla.
why? Can u explain this? Thx.

PandaBambuuu
Автор

I want to know if I writing in module2, how to import module5?
"from package2.subpackage import module5" seems to wrong..

ayixi
Автор

Is there a clean way to import module1 from module5 without messing with sys.path ?

stoufa
Автор

WTF DOES THIS MEAN!?!? ImportError: attempted relative import with no known parent package
I"M DOING AN ABSOLUTE IMPORT

Blxxy
Автор

How do i see what is inside import from other device

Tcalma
Автор

Hey thanks for vedio, but I tried like this but got package 2 not found import error, how to deal it, I am handling this by adding the path of folders package 2 and other to environment variable PYTHONPATH

manojs
Автор

Stupid ad where donkey is the size of the castle wall. Okay.

atlantic_love