Вторая по частоте future-функция, которую я использовал, это абсолютный импорт
from __future__ import absolute_import
Что она делает?
Изменения, которые вносит эта инъекция описаны в PEP328
Покажу простой пример.
Допустим, есть такой пакет:
/my_package
/__init__.py
/main.py
/string.py
Смотрим код в my_package/main.py
# main.py
import string
Простой пример готов) Вопрос в том, какой модуль импортируется в данном случае? Есть два варианта:
1. модуль в моём пакете my_package.string
2. стандартный модуль string
И вот тут вступает в дело приоритет импортов. В Python2 порядок следующий: помимо иных источников, раньше ищется модуль внутри текущего пакета, а потом в стандартных библиотеках. Таким образом мы импортнём my_package.string.
Но в Python3 это поведение изменилось. Если мы указываем просто имя пакета, то ищется именно такой модуль, игнорируя имена в текущем пакете. Если мы хотим импортнуть именно подмодуль из нашего пакета то, мы должны теперь явно это указывать.
from my_package import string
или относительный импорт, но с указанием пути относительно текущего модуля main
from . import string
Еще одной неоднозначностью меньше 😎
Подробней про импорты здесь:
https://docs.python.org/3/tutorial/modules.html
#2to3#pep#basic
Every parent needs to listen to this life-changing tip from PM Modi! Let your children make their choices in life & make their own path
👉 To listen to more mantras of success, Don't forget to watch #PPC2023 on 27th Jan 2023
https://youtu.be/Fwdx_cBqiDU
Every parent needs to listen to this life-changing tip from PM Modi! Let your children make their choices in life & make their own path
👉 To listen to more mantras of success, Don't forget to watch #PPC2023 on 27th Jan 2023
https://youtu.be/Fwdx_cBqiDU
परीक्षा से पहले की तैयारियों को लेकर अब बिल्कुल न हो परेशान; क्योंकि प्यारे बच्चों जल्द आ रहा है प्रधानमंत्री के साथ परीक्षा पे चर्चा 2023 संवाद।
#PPC2023
https://youtu.be/SKmrRc2-QTQ
अपने पैशन को चुनें या एक अच्छे करियर की प्लानिंग करें?
करियर या परीक्षा से जुड़े आपके सभी सवालों के पीएम 27 जनवरी 2023 को देंगे जवाब। #PPC2023
https://youtu.be/RzB7PY4VX0w
विजिट करें: mygov.in/ppc-2023/
परीक्षा से डरने के बजाय मुस्कुराते हुए उसे अपना बनाएं।
27 जनवरी, 2023 को #PPC2023 में प्रधानमंत्री के टिप्स से परीक्षा या करियर से जुड़े आपके हर सवाल का मिलेगा समाधान।
#PPC2023
👆Wondering how to create a perfect balance of studies and sports for your children during exams? PM Modi is here to help
Participate in #PPC2023 and get tips on dealing with your children's exam stress!
Visit: innovateindia.mygov.in/ppc-2023/
👆Become the best coach, mentor and teacher of your children with the help of PM's tips and advice!
Participate in #PPC2023 and make your children exam ready
Visit: https://innovateindia.mygov.in/ppc-2023/
परीक्षा के मुश्किल दिनों को बनाएं खुशनुमा और तनावमुक्त। परीक्षा पे चर्चा 2023 में शामिल होने के लिए भेजें अपने सुझाव और सवाल, आपको मिल सकता है प्रधानमंत्री से सीधे संवाद का मौका।
#PPC2023
https://youtu.be/YcV_uea2ok8
👆Become the best coach, mentor and teacher of your children with the help of PM's tips and advice!
Participate in #PPC2023 and make your children exam ready
Visit: https://innovateindia.mygov.in/ppc-2023/
👆Help your children reach their maximum potential this exam season, with PM Modi's inspiring advice!
👉 Participate in #PPC2023 and make your children exam ready.
Visit: https://innovateindia.mygov.in/ppc-2023/
👆Become the best coach, mentor and teacher of your children with the help of PM's tips and advice!
Participate in #PPC2023 and make your children exam ready
Visit: https://innovateindia.mygov.in/ppc-2023/