PYTHONL Telegram 4919
This media is not supported in your browser
VIEW IN TELEGRAM
🧠 Ускорь import в Python-проектах с помощью lazy loading — без изменения логики

Если у тебя проект с тяжёлыми модулями (`pandas`, torch, tensorflow`), но они не всегда нужны — не загружай их зря. Python позволяет **отложить импорт до первого использования**, через встроённый `importlib.

Вот как это выглядит на практике:



import importlib

# Обёртка для ленивого импорта
def lazy_import(name):
return importlib.util.LazyLoader(importlib.import_module(name))

# Использование
np = lazy_import('numpy')
# numpy ещё не загружен

# Теперь загрузится:
print(np.array([1, 2, 3]))


@pythonl
29👍14🔥4



tgoop.com/pythonl/4919
Create:
Last Update:

🧠 Ускорь import в Python-проектах с помощью lazy loading — без изменения логики

Если у тебя проект с тяжёлыми модулями (`pandas`, torch, tensorflow`), но они не всегда нужны — не загружай их зря. Python позволяет **отложить импорт до первого использования**, через встроённый `importlib.

Вот как это выглядит на практике:



import importlib

# Обёртка для ленивого импорта
def lazy_import(name):
return importlib.util.LazyLoader(importlib.import_module(name))

# Использование
np = lazy_import('numpy')
# numpy ещё не загружен

# Теперь загрузится:
print(np.array([1, 2, 3]))


@pythonl

BY Python/ django


Share with your friend now:
tgoop.com/pythonl/4919

View MORE
Open in Telegram


Telegram News

Date: |

While some crypto traders move toward screaming as a coping mechanism, many mental health experts have argued that “scream therapy” is pseudoscience. Scientific research or no, it obviously feels good. End-to-end encryption is an important feature in messaging, as it's the first step in protecting users from surveillance. In handing down the sentence yesterday, deputy judge Peter Hui Shiu-keung of the district court said that even if Ng did not post the messages, he cannot shirk responsibility as the owner and administrator of such a big group for allowing these messages that incite illegal behaviors to exist. The Standard Channel Add the logo from your device. Adjust the visible area of your image. Congratulations! Now your Telegram channel has a face Click “Save”.!
from us


Telegram Python/ django
FROM American