PYTHON_JOB_INTERVIEW Telegram 1147
This media is not supported in your browser
VIEW IN TELEGRAM
⚙️ Подменяй любые импорты в Python “на лету” — без изменения кода

Если ты хочешь протестировать модуль, подменить зависимость, замокать внешний сервис или обмануть импорт — не обязательно редактировать исходники. Python позволяет перехватывать импорты прямо во время выполнения, через sys.modules.

Вот минимальный приём, который делает это прозрачно:


import sys
import types

# Создаём фейковый модуль
fake = types.SimpleNamespace()
fake.get_data = lambda: "подмена работает"

# Подменяем импорт
sys.modules['external_service'] = fake

# Теперь даже import будет работать
import external_service
print(external_service.get_data()) # → "подмена работает"
🔥64👍2🥰1



tgoop.com/python_job_interview/1147
Create:
Last Update:

⚙️ Подменяй любые импорты в Python “на лету” — без изменения кода

Если ты хочешь протестировать модуль, подменить зависимость, замокать внешний сервис или обмануть импорт — не обязательно редактировать исходники. Python позволяет перехватывать импорты прямо во время выполнения, через sys.modules.

Вот минимальный приём, который делает это прозрачно:


import sys
import types

# Создаём фейковый модуль
fake = types.SimpleNamespace()
fake.get_data = lambda: "подмена работает"

# Подменяем импорт
sys.modules['external_service'] = fake

# Теперь даже import будет работать
import external_service
print(external_service.get_data()) # → "подмена работает"

BY Python вопросы с собеседований


Share with your friend now:
tgoop.com/python_job_interview/1147

View MORE
Open in Telegram


Telegram News

Date: |

2How to set up a Telegram channel? (A step-by-step tutorial) The imprisonment came as Telegram said it was "surprised" by claims that privacy commissioner Ada Chung Lai-ling is seeking to block the messaging app due to doxxing content targeting police and politicians. Unlimited number of subscribers per channel Telegram has announced a number of measures aiming to tackle the spread of disinformation through its platform in Brazil. These features are part of an agreement between the platform and the country's authorities ahead of the elections in October. Deputy District Judge Peter Hui sentenced computer technician Ng Man-ho on Thursday, a month after the 27-year-old, who ran a Telegram group called SUCK Channel, was found guilty of seven charges of conspiring to incite others to commit illegal acts during the 2019 extradition bill protests and subsequent months.
from us


Telegram Python вопросы с собеседований
FROM American