Вторая по частоте 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
Jake Paul knocked out Mike Perry in the 6th round 👊
I expected to win. I should have won in the first round, but Perry survived. Mike Tyson, you're next, sign the contract.
#Box
👁Subscribe to Main Event | Sport News
Jake Paul on the fight with Mike Perry:
"Maybe at the beginning, he’ll land a couple of heavy shots, maybe he’ll be all wild and unpredictable, but as the fight progresses, I’ll start breaking him down with my footwork, jab, and body shots."
#Box
👁Subscribe to Main Event | Sport News
Diaz Sues Organizers of Fight with Masvidal
#box#mma
Nate Diaz has filed a lawsuit against the organizers of the fight with Jorge Masvidal.
Nate claims he had an agreement for a $10,000,000 payout for the fight. He received an advance payment of $1,000,000, with the remaining $9,000,000 to be paid after the fight. The lawsuit states that the company is refusing to make the payments, claiming that the event was unprofitable.
👁Subscribe to Main Event | Sport News