Подразумеваемые неймспейсы или неявные пакеты.
Этот функционал добавлен в 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
“When they attacked some village, they called all the people to one place. ‘Everyone must follow us and our religion. If not, we must shoot you,’” says Khuseini from Nigeria about Boko Haram terrorists.
This criminal group is responsible for killing thousands of people. Khuseini and his family fled their hometown when Boko Haram arrived. Now he lives in the Dar es Salaam refugee camp and teaches Arabic to kids at the local school. Khuseini says the kids are deeply traumatised by the terrorists’ brutality. They remember how Boko Haram attacked their town, killing their friends. There are machine guns, blood, and killings even in kids’ drawings.
Today is Children’s Day in Nigeria. Watch the clip to see how kids – Boko Haram’s victims - live in the refugee camp and try to get back to everyday life. Then, find out more in our documentary Hot Spot Chad.
#crime
Follow: https://t.me/rtdocumentary
‘He’s not resisting arrest; he’s on the ground. You’ve him in handcuffs. Why is there a need to hit him in the back with a rifle?’ – asks a desperate mother whose child died due to police brutality. Quincy and his girlfriend argued, he left the house, leaving her angry. She called the police and told them he had a rifle. That fatal lie cost Quincy his life. Five police officers didn’t even intend to find out the truth but tackled and beat the young man to death.
Cases like this are common in the USA. Hundreds of people die every year at the hands of law enforcement officers. Watch the clip to see some cases. Do you think it’s possible to change the situation? See the documentary Once Upon A Crime to learn what people do to stop police brutality.
#crime
Follow: https://t.me/rtdocumentary
🎬 Adolescence
Gênero: #Crime, #Drama
⭐️ IMDb: 8.1
⏳ Duração: 15 Episódios
📝 Sinopse:
Quando um garoto de 13 anos é acusado do assassinato de um colega de classe, sua família, o terapeuta e o detetive responsável ficam perguntando o que realmente aconteceu.
Fonte: IMDb
🔵Inscreva-se em @Assistir
*Patrocinado: Anime Bot
🍿 'The Penguin': The Most Anticipated Spin-off of 'The Batman' 🎬
📆Premiere: September 19, 2024
🎭Genre: #Crime · #Drama
Colin Farrell dives into the role of Oz Cobb, aka The Penguin, in this series that promises to expand the universe of Matt Reeves' 'The Batman.' With 3.5 hours of daily makeup, Farrell transforms into Gotham's crime boss. The trailer, unveiled at Comic-Con, left everyone in awe. 🎥
The interesting part is how Reeves initially planned a series for DC, and HBO finally made it happen. Cristin Milioti and Rhenzy Feliz join Farrell in an impressive cast. And watch out! The Penguin will return in 'The Batman II' in 2026. 🦇✨
🍿The Penguin: Colin Farrell Returns to Gotham
📆Release: Fall 2024
🎭Genre: #Crime · #Drama
The new trailer for 'The Penguin' brings Colin Farrell back as Gotham's infamous gangster, Oswald Cobblepot. This spin-off from Matt Reeves' 'The Batman' follows Cobblepot's rise to power after the death of Carmine Falcone. 🚦🔫
What's really fascinating is how Farrell's makeup has evolved, giving him an even more menacing look true to the iconic DC villain. Plus, the brewing tension with Sofia Falcone, played by Cristin Milioti, promises electrifying drama. Don't miss this thriller, which is already shaping up to be a hit. 🌆🔥
> 𝘴𝘦𝘳𝘪𝘦𝘴 · 🚀𝘣𝘰𝘰𝘴𝘵