Вторая по частоте 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
🌎 In Costa Rica, the golden orb-weaver spider spins silk that glows bright gold in sunlight. This strong, shimmering web attracts pollinating insects while reflecting UV light, making it both a trap and a natural artwork. ✨
#spiders⚡#biodiversity⚡#adaptation
👉subscribe Interesting Planet
🌎 Peacock spiders from Australia show off bold, iridescent colors during their unique courtship dances. Males raise flaps on their abdomen that resemble tiny rainbows to attract females. Over 80 species have been identified, each with distinct colors and patterns. ✨
#animals⚡#camouflage⚡#spiders
👉subscribe Interesting Planet
🌎 A single strand of spider silk is so thin and strong that, if scaled up, it could stop a speeding jet airliner. Spider silk’s unique proteins give it greater tensile strength than steel, making it a model for future lightweight materials. ✨
#spiders⚡#biomaterials⚡#engineering
👉subscribe Interesting Planet
🌎 The silk of the Darwin's bark spider, found in Madagascar, is the toughest biological material known—over 10 times stronger than Kevlar used in bulletproof vests. ✨
#spiders⚡#materials⚡#Madagascar
👉subscribe Interesting Planet
Arachnophobia or the fear of spiders is the oldest and most common phobia in the Western culture. The word Arachnophobia is derived from the Greek word ‘arachne’ meaning spiders.
🕷🕸
[Learn more]
@googlefactss
#spiders#fear#HumanMind
The world’s biggest spiderweb—home to 111,000+ spiders— is found in the Cave of Sulphur on the Albanian–Greek border. Two common species built a massive colonial cobweb in a permanently dark zone—the first record of cooperative web-building at this scale. Researchers call for preservation and are preparing follow-up studies. 🕷️🕸️🌍🇦🇱🇬🇷
[Read more here]
@googlefactss
#Nature#Discovery#Spiders#Conservation
Jumping spiders are small spiders in the Salticidae family. They have four pairs of eyes, with large front eyes for hunting and navigation. They do not build webs to catch prey. They hunt by stalking and leaping on insects. They use silk as a safety line when they jump. Some species are kept as pets and are easy to care for.
🕷️🌿🎯
[Read more]
@googlefactss
#Spiders#JumpingSpider#Salticidae#Nature#Pets