Многие из тех кто активно работал с Python2 несколько удивлены, почему в Python3 удобная функция reload() переехала из builtin в imp а потом и в importlib?
Ну было же удобно! А теперь лишний импорт😖
Дело в том, что начиная с Python3.3 функция reload() переписана на Python вместо Cи.
Что это нам даёт?
🔸 Такой код проще поддерживать и развивать
🔸 Python код легче читать, изучать и понимать.
Сравните это ➡️ и это ➡️.
🔸 Как результат пункта 2, проще писать свои расширения импорта. Например, пользовательский импортёр с какой-либо хитрой логикой по аналогии с импортом из zip архивов.
А есть ли у этого решения недостатки? Да, они всегда есть.
🔹 Так как это не builtin функция, её следует импортнуть перед использованием
🔹 Скорость замедлилась примерно на 5%. Очевидно, что это совершенно не критично. К тому же от версии к версии логика импорта будет оптимизироваться и ускоряться.
В самом начале файла importlib/__init__.py мы видим такой импорт:
import _imp # Just the builtin component, NOT the full Python module
То есть часть функционала по прежнему написана на Си, но достаточно низкоуровневая.
#basic
🌎 In Slovenia, the Postojna Cave system stretches over 24 kilometers and features an electric railway for visitors. Completely formed by the Pivka River, its labyrinth includes massive chambers and rare olm salamanders, which can live over 100 years in total darkness. ✨
#caves⚡#geology⚡#salamander
👉subscribe Interesting Planet
👉more Channels
🌎 The lungless salamander breathes entirely through its skin and mouth lining—no lungs at all! This adaptation lets it thrive in moist forests, where constant skin moisture is key for gas exchange and silent hunting. ✨
#salamander⚡#adaptation⚡#evolution
👉subscribe Interesting Planet
🌎 Deep in the caves of Slovenia, the olm lays eggs that take up to 6 years to develop! This cave salamander lives in total darkness, using keen senses of smell and vibration to survive, and can go years without food. ✨
#salamander⚡#caves⚡#evolution
👉subscribe Interesting Planet
🌎 The Japanese giant salamander can grow over 1.5 meters long, making it one of the largest amphibians on Earth. This gentle, nocturnal creature breathes through loose skin folds which help it absorb oxygen from cold, fast-flowing streams. ✨
#salamander⚡#wildlife⚡#Japan
👉subscribe Interesting Planet
🌎 The giant salamander of China is the world’s largest amphibian, reaching 1.8 meters in length. Its ancestors appeared about 170 million years ago, and it can live over 50 years in the wild. ✨
#salamander⚡#fossil⚡#amphibian
👉subscribe Interesting Planet
👉more Channels