Подразумеваемые неймспейсы или неявные пакеты.
Этот функционал добавлен в 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
🌍 Earth’s gravity is just strong enough to keep an atmosphere and liquid water, but not so strong that gases like hydrogen escape quickly. This balance is rare among rocky planets in our Solar System. ✨
#earth⚡#planet⚡#gravity⚡#geography⚡#nature
👉subscribe Amazing Geography
👉more Channels
🌎 The Great Attractor is a mysterious gravitational anomaly in the universe, pulling our Milky Way and thousands of galaxies towards it at over 600 kilometers per second. This region lies about 150 million light-years away in the direction of the constellation Centaurus, but it is largely hidden by the dense dust and stars of our own galaxy, making its true nature still unknown. ✨
#space⚡#astronomy⚡#gravity
👉subscribe Interesting Planet
👉more Channels
🪐 The cosmic microwave background contains a hidden signature called the "Sachs-Wolfe effect," where variations in temperature are linked to the gravitational pull of massive structures like galaxy clusters. This effect, first detected in the 1990s using data from the COBE and WMAP satellites, shows how even the oldest light in the universe was influenced by the invisible gravity of objects such as the Coma Cluster and the Great Attractor, providing a glimpse into how matter was distributed across the cosmos more than 13 billion years ago. ✨
#cosmology⚡#gravity⚡#universe⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 In the galaxy cluster known as the Bullet Cluster (1E 0657-56), a cosmic collision has split ordinary matter—seen as hot X-ray gas—from invisible dark matter, which can only be traced by its gravity. By observing how light from background galaxies bends around the Bullet Cluster, astronomers have created detailed maps showing where dark matter gathers, making this system a real, visual proof that most of the universe’s mass is hidden and does not emit light. ✨
#darkmatter⚡#galaxies⚡#gravity⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Astronomers have measured that the Coma Cluster—a giant gathering of thousands of galaxies—stays held together by vast amounts of dark matter, an invisible substance that can't be seen but adds enough gravity to keep the cluster from flying apart. Despite all the stars and gas we observe, dark matter in the Coma Cluster outweighs everything visible by more than five times, showing how this hidden ingredient shapes the largest structures in the universe. ✨
#darkmatter⚡#galaxies⚡#gravity⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The spiral galaxy NGC 3198 has helped scientists map the mysterious effects of dark matter—a hidden substance that doesn't emit light, but has enough gravity to control how stars move far from the galaxy's center. By tracing the speeds of stars in NGC 3198’s outer edges, astronomers found they move much faster than visible matter alone can explain, revealing an invisible halo of dark matter wrapped around the galaxy. ✨
#darkmatter⚡#galaxies⚡#gravity⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The supermassive black hole at the center of the Milky Way, Sagittarius A*, was observed by the GRAVITY instrument on the Very Large Telescope in 2018, revealing that blobs of hot gas orbit just outside its event horizon at about 30% the speed of light. This close-up look confirmed extreme gravity effects predicted by Einstein, and for the first time, scientists watched matter whip around a black hole in real time just kilometers from the point of no return. ✨
#blackholes⚡#gravity⚡#milkyway⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Astronomers have observed an unusual form of space-time distortion called "frame dragging" around the rapidly spinning black hole in the galaxy XTE J1550–564. Frame dragging is an effect predicted by Einstein’s relativity, where a rotating massive object actually twists nearby space and time, causing the orbits of matter and light around it to precess—showing in real life how intense gravity can physically drag space itself into motion. ✨
#wormholes⚡#spacetime⚡#gravity⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 In 2015, astronomers using the Hubble Space Telescope watched star light from behind the galaxy cluster Abell 3827 bend and split as it passed through the cluster, a real-life effect of space-time distortion called gravitational lensing. Gravity from massive clusters like Abell 3827 warps the space around them, so light takes curved paths and can appear as multiple, stretched images—direct evidence that space itself can be bent by gravity’s pull. ✨
#wormholes⚡#spacetime⚡#gravity⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 On Jupiter, time actually ticks a little faster than on Earth! Because Jupiter is much less dense and has weaker gravity at its cloud tops, its gravitational pull slows time down less than Earth's gravity does—a real effect called gravitational time dilation, where clocks in stronger gravity run slower compared to those farther away from massive objects. ✨
#timedilation⚡#jupiter⚡#gravity⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries