Подразумеваемые неймспейсы или неявные пакеты.
Этот функционал добавлен в Python 3.3
Что он означает?
Ранее, до 3.3 пакетами считались лишь директории, в которых есть файл __init__.py.
Этот файл одновременно являлся свидетельством того, что директория это Python-пакет, и служил "телом" этого пакета. То есть местом, где можно написать код, как это делается внутри модуля. Этот код исполняется в момент импорта пакета, так что его принято называть "код инициализации пакета".
Начиная с версии 3.3 Любая директория считается пакетом и Python будет пытаться использовать любую директорию для импорта.
Конечно, не любую в файловой системе, а только те что находятся в sys.path.
Это значит, что теперь __init__.py нужно делать только если:
🔸 вам требуется создать код инициализации пакета
🔸 нужна совместимость со старыми версиями Python
На мой взгляд это немного упрощает разработку, делает её чище, но с другой стороны убивает некоторую однозначность происходящего.
Например, я создал репозиторий со своей библиотекой и рядом положил код примеров или тестов.
repo_name/
my_library/
__init__.py
main.py
examples/
exam1.py
exam2.py
В этом репозитории пакетом является только my_library, остальные директории это не пакеты, это просто дополнительный код в файлах. Директория examples не добавлена в sys.path, в ней нет рабочих модулей. Но если она лежит рядом с my_library, то Python вполне сможет импортнуть из неё модули, так как посчитает что examples это валидный пакет.
Конечно, пример несколько надуманный. Никто не будет добавлять корень репозитория в sys.path. Но, я думаю, суть ясна. Иногда директория это просто директория а не пакет!
#basic#pep
🌍 Some rainforest insects mimic leaves so perfectly they even show “bite marks” or rot spots on their bodies, hiding from predators in the dense, shadowy understory. ✨
#rainforest⚡#biodiversity⚡#adaptation⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Terraced vineyards on Portugal's Douro River show how people reshape steep hillsides for farming. Ancient stone walls protect soil from erosion while letting grape vines thrive in harsh terrain. ✨
#agriculture⚡#landscape⚡#adaptation⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Terraced rice fields in Southeast Asia transform steep hillsides into farmable land, reducing soil erosion and creating unique landscapes shaped by both nature and human ingenuity. ✨
#agriculture⚡#landscape⚡#adaptation⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌎 The male seahorse is the only animal where the male becomes pregnant, carrying fertilized eggs in a special pouch until they hatch. Seahorses can give birth to hundreds of fully formed young at a time—up to 2,000 in a single brood. ✨
#adaptation⚡#animals⚡#ocean
👉subscribe Interesting Planet
👉more Channels
🌍 In tundra landscapes, some mosses and lichens can survive temperatures below –50°C and continue to photosynthesize under snow, making them some of the Earth’s hardiest plants. ✨
#tundra⚡#permafrost⚡#adaptation⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 The Galápagos Islands are home to the only marine iguanas on Earth. These unique lizards swim and dive in the Pacific Ocean, making them the world’s only sea-going reptiles. ✨
#islands⚡#wildlife⚡#adaptation⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Urban green roofs, where buildings are topped with plants, help cities manage rainwater, reduce heat, and provide habitats for birds and insects, blending urban life with nature. ✨
#cities⚡#environment⚡#adaptation⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 In tropical rainforests, some plant leaves grow waxy surfaces and pointed tips called "drip tips." These features help water run off quickly, stopping mold and fungi in the damp climate. ✨
#rainforest⚡#tropics⚡#adaptation⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Earth’s climate zones are not just about temperature—they also shape which plants and animals can survive. Some cacti thrive in deserts, while rainforests burst with life in tropical zones. ✨
#climate⚡#vegetation⚡#adaptation⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌎 The star-nosed mole detects prey in total darkness using its unique nose, covered in 22 finger-like tentacles packed with touch sensors. This extraordinary adaptation lets it identify and eat tiny insects and worms faster than any other mammal, even underwater. ✨
#animals⚡#adaptation⚡#evolution
👉subscribe Interesting Planet
🌍 Tropical savannas can burn naturally every 1–3 years, yet some species, like the baobab tree, thrive by storing water in thick trunks to survive both drought and fire. ✨
#savanna⚡#grassland⚡#adaptation⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 In Chile's Atacama Desert, rare fog called "camanchaca" drifts inland from the Pacific. Some plants here survive by absorbing water directly from this fog, not from rainfall. ✨
#desert⚡#arid⚡#adaptation⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels