Подразумеваемые неймспейсы или неявные пакеты.
Этот функционал добавлен в 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
❌🟠 Los Giants no anticipan hacer un contrato de nueve cifras para Tatsuya Imai ni para ningún otro lanzador en el mercado esta temporada baja, según Andrew Baggarly.
#️⃣#Giants
🗞 | t.me/MLB_Daily
🏥🌉 Los Giants están colocando a Logan Webb en la lista de lesionados con bursitis en la rodilla derecha, según Alex Pavlovic de NBC Sports Bay Area.
Es la primera vez que Webb está en la lista de lesionados desde 2021.
#Giants#LWebb
🗞 | t.me/MLB_Daily
🟠🤠 Según varios informes, incluidos los de Mark Feinsand de MLB.com, los Giants y el lanzador derecho Tyler Mahle han acordado un contrato de un año.
#️⃣#Giants#Mahle
🗞 | t.me/MLB_Daily
🟠 Según Ken Rosenthal, se informa que los San Francisco Giants están cerca de contratar a Tony Vitello, entrenador principal de Tennessee, como su nuevo manager.
#️⃣#Giants#Vitello
🗞 | t.me/MLB_Daily
🌎 The coconut crab is the world’s largest land-dwelling arthropod, able to crack open coconuts with its powerful pincers. These giant crabs live on islands across the Indo-Pacific, and their climbing and shell-breaking skills help them access food that other animals can’t reach. ✨
#animal⚡#giants⚡#adaptation⚡#islands
👉subscribe Interesting Planet
🪐 Unlike Earth and Mars, giant planets like Jupiter and Saturn do not have solid surfaces—their thick outer layers are made mostly of hydrogen and helium gas, which gradually becomes denser toward the center. These gas giants can have dozens of moons and faint ring systems, and their powerful magnetic fields—especially Jupiter’s, which is the strongest of any planet in our solar system—can trap charged particles, creating intense radiation belts that glow in radio waves. ✨
#Jupiter⚡#Saturn⚡#giants⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Jupiter, the largest planet in our solar system, is so massive that it has over twice the combined mass of all the other planets put together. Its rapid rotation—completing one spin every 10 hours—causes it to bulge noticeably at the equator, creating a distinct flattened shape unlike the more spherical profiles of smaller planets. ✨
#Jupiter⚡#giants⚡#rotation⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Saturn’s rings are made mostly of icy particles ranging from the size of grains of sand to mountains, but what’s remarkable is that these rings are incredibly thin—often only about 10 meters thick compared to their width of up to 282,000 kilometers. Despite their vast size, the rings would still fit comfortably within the gap between Earth and the top of our atmosphere if laid flat. ✨
#Saturn⚡#rings⚡#giants⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels