Подразумеваемые неймспейсы или неявные пакеты.
Этот функционал добавлен в 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
🪐 One of the largest comets ever observed, C/2014 UN271 (Bernardinelli-Bernstein), is traveling through our solar system and is estimated to be about 150 kilometers wide—over 1,000 times bigger than a typical comet. Although it won't come close enough to threaten Earth, its sheer size shows that massive objects from the far reaches of the solar system, like the distant Oort Cloud, could pose a significant risk if their paths ever brought them near our planet. ✨
#comets⚡#oortcloud⚡#threats⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
Global Central Banks Booed Trump for His Threats Against Powell
Global central banks have issued an extraordinary joint statement offering “full solidarity” to the US Federal Reserve chair, Jerome Powell, in the face of the latest threat to his independence from Donald Trump’s White House.
“The independence of central banks is a cornerstone of price, financial and economic stability in the interest of the citizens that we serve. It is therefore critical to preserve that independence, with full respect for the rule of law and democratic accountability,” the statement said.
It was signed by nine central bank governors including the Bank of England governor, Andrew Bailey, and the chair of the European Central Bank, Christine Lagarde.
It was coordinated by the Basel-based Bank for International Settlements, which added its chair and general manager to the signatories.
Other signatories to the unprecedented statement include the central bank governors of Australia, Sweden, Denmark, Switzerland, Brazil, South Korea and Canada. More names are expected to be added later on Tuesday.
They pay testament to Powell’s “integrity” and “unwavering commitment to the public interest”, calling him a “respected colleague who is held in the highest regard by all who have worked with him”.
Trump has repeatedly criticised Powell, whom he appointed in 2018, for failing to cut interest rates fast enough.
But the clash between the two men took a dramatic turn earlier this week when Powell issued a strongly worded video statement, saying he was being prosecuted by the US Department of Justice.
He said he had been singled out because the Fed’s policymaking board had set interest rates “based on our best assessment of what will serve the public, rather than following the preferences of the president”.
Trump has moved to distance himself from the investigation, however, claiming he was unaware of it. “I don’t know anything about it,” he told NBC News.
Powell is due to step down as chair of the Fed board in May, and Trump is expected to announce his successor in the coming weeks.
The former Fed chairs Alan Greenspan, Ben Bernanke and Janet Yellen had already condemned the threat to Powell on Monday, saying the move could have “highly negative consequences”.
“This is how monetary policy is made in emerging markets with weak institutions, with highly negative consequences for inflation and the functioning of their economies more broadly,” their statement said.
#trump#central#banks#threats#powell
📱American Оbserver - Stay up to date on all important events
🇺🇸
Navigating AI Opportunities & Threats
Explore how AI presents both challenges and opportunities for small businesses. While larger firms dominate the market, many entrepreneurs can thrive with modest revenue targets. AI could lead to the decline of SaaS businesses due to cost-effective alternatives. However, it allows individuals to quickly replicate and improve existing applications, catering to proven market needs. Though scaling to $500M ARR is tough in niches, a small investment can create meaningful products. Innovators can introduce multiple unique offerings, even in shadow of larger tech giants.
#AI#SaaS#Business#Investment#Tech#Entrepreneurship#Revenue#ProductDevelopment#Innovation#Market#Growth#Web3#Startups#Opportunity#Threats#SmallBusiness#Investors#ExistingMarket#Applications#PMF#CostEfficiency