Тёмный

Absolute Imports in Python 

Real Python
Подписаться 193 тыс.
Просмотров 24 тыс.
50% 1

Опубликовано:

 

11 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 20   
@Norfeldt
@Norfeldt 4 года назад
Where is the next video about relative imports?
@PandaBambuuu
@PandaBambuuu 3 года назад
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.
@voyageintostars
@voyageintostars 2 года назад
Hey! I have the same issue, did you get any answer??
@ayixi6
@ayixi6 5 лет назад
I want to know if I writing in module2, how to import module5? "from package2.subpackage import module5" seems to wrong..
@Thelaunius
@Thelaunius 4 года назад
Did you find an answer to this question? I have the same problem...
@RohitDhavade
@RohitDhavade 4 года назад
This was the only challenge I came to this video but the examples given in the video are too simple. Did you get a solution to your query ?.
@RohitDhavade
@RohitDhavade 4 года назад
@Real Python .. can you answer this query ??
@spawndli1410
@spawndli1410 8 месяцев назад
Hey man did you ever find an answer , most RU-vid videos explain everything that one can figure out on their own...complex examples
@stoufa
@stoufa 5 лет назад
Is there a clean way to import module1 from module5 without messing with sys.path ?
@Thelaunius
@Thelaunius 4 года назад
Did you find an answer to this question? I have the same problem and I cannot find an answer...
@atlantic_love
@atlantic_love 4 года назад
@@Thelaunius Having the same issue here. This is EXACTLY why Python is a "toy" programming environment. Literally you can only either: (a) upload your python files to pypi to be used by others, or (b) keep python files that you want to "import" in the same directory (or a subdirectory ) as your working program. Literally, all data science and all that is done in this "sandbox" created by Python. This is why the language can't be taken seriously.
@sreehari563
@sreehari563 3 года назад
@@atlantic_love Hi, In case this is still helpful to you guys or to anybody else who is going to read this in future, I wish to clarify that, as far as my understanding goes, relative imports mostly and even sometimes absolute imports in Python will almost always result in an error if we try to run a particular file having import statement directly from the command prompt( same scenario in most IDE's too). If we are developing some sort of application and we organize our files into different folders/packages correctly as is illustrated in this video, then we would of course have a file at the top level that starts our application. Only that file can and should be run directly from command prompt. For all other non library/application projects that you do in python, simply put all the module files in the same folder and call them as per requirement in any file using direct import statements. So during the development of your library/app you can follow this approach in order to ensure that each module is working properly and once all work including the top level file that starts the app is done, you can then proceed to organize them into folders/packages and add the required absolute/relative import statements. Then simply test out your whole app. Relative imports still remains an area of python where a google search would only leave someone in even more darkness.
@Tcalma
@Tcalma 3 года назад
How do i see what is inside import from other device
@Bl0xxy
@Bl0xxy 3 года назад
WTF DOES THIS MEAN!?!? ImportError: attempted relative import with no known parent package I"M DOING AN ABSOLUTE IMPORT
@manojs157
@manojs157 5 лет назад
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
@raphaelstascheit6239
@raphaelstascheit6239 4 года назад
You are probably using python2 where you need an __init__.py file in your package folder to make it known to the interpreter as importable resource. You can make sure which version you are using with `import sys` and `print(sys.version)`
@dennisasamoah2213
@dennisasamoah2213 4 года назад
great
@dmmeteo
@dmmeteo 5 лет назад
First comment is mine!:)
@atlantic_love
@atlantic_love 4 года назад
Stupid ad where donkey is the size of the castle wall. Okay.
Далее
Unlocking your CPU cores in Python (multiprocessing)
12:16
Cute
00:16
Просмотров 6 млн
BeastMasters Hawk just had enough #ti13
00:30
Просмотров 358 тыс.
Top 18 Most Useful Python Modules
10:50
Просмотров 929 тыс.
Absolute and Relative imports - Python Tutorial 28
14:02
How To Master Python
14:47
Просмотров 1 млн
Best Practices for Python Main Functions
11:17
Просмотров 183 тыс.
Python GUI Development With PySimpleGUI
15:15
Просмотров 1 млн
Cute
00:16
Просмотров 6 млн