Telegram Group & Telegram Channel
Создаем контекстный менеджер с помощью декоратора

Обычно протокол управления контекстом реализовывают с помощью класса и двух магических методов: __enter__ и __exit__. Но такой подход может показаться слегка сложным.

Так вот, помимо написания своего класса, есть еще один способ создать контекстный менеджер — использовать декоратор @contextmanager из встроенного пакета contextlib.

Первая часть функции tag, которая идёт до yield, выполняется при входе в блок with. Затем исполняется сам этот блок, а после этого завершается оставшаяся часть, которая идет после yield.

 #contextlib



tg-me.com/python_academy/1271
Create:
Last Update:

Создаем контекстный менеджер с помощью декоратора

Обычно протокол управления контекстом реализовывают с помощью класса и двух магических методов: __enter__ и __exit__. Но такой подход может показаться слегка сложным.

Так вот, помимо написания своего класса, есть еще один способ создать контекстный менеджер — использовать декоратор @contextmanager из встроенного пакета contextlib.

Первая часть функции tag, которая идёт до yield, выполняется при входе в блок with. Затем исполняется сам этот блок, а после этого завершается оставшаяся часть, которая идет после yield.

 #contextlib

BY Python Academy




Share with your friend now:
tg-me.com/python_academy/1271

View MORE
Open in Telegram


Python Academy Telegram | DID YOU KNOW?

Date: |

Can I mute a Telegram group?

In recent times, Telegram has gained a lot of popularity because of the controversy over WhatsApp’s new privacy policy. In January 2021, Telegram was the most downloaded app worldwide and crossed 500 million monthly active users. And with so many active users on the app, people might get messages in bulk from a group or a channel that can be a little irritating. So to get rid of the same, you can mute groups, chats, and channels on Telegram just like WhatsApp. You can mute notifications for one hour, eight hours, or two days, or you can disable notifications forever.

However, analysts are positive on the stock now. “We have seen a huge downside movement in the stock due to the central electricity regulatory commission’s (CERC) order that seems to be negative from 2014-15 onwards but we cannot take a linear negative view on the stock and further downside movement on the stock is unlikely. Currently stock is underpriced. Investors can bet on it for a longer horizon," said Vivek Gupta, director research at CapitalVia Global Research.

Python Academy from us


Telegram Python Academy
FROM USA