Telegram Group & Telegram Channel
​​Создаём свой контекстный менеджер

Привет, в четверг на канале вышел небольшой пост про контекстные менеджеры. Сейчас разберём, как их можно реализовать.

В любом контекстном менеджере должны быть определены методы __enter__ и __exit__. В качестве примера создадим подобие уже существующего open.

Метод __enter__ вызывается автоматически и возвращает объект файла. После того, как блок with заканчивается, также вызывается метод __exit__, который закрывает файл.

А более подробно мы рассказываем про эту тему в нашем курсе по продвинутым темам.



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

​​Создаём свой контекстный менеджер

Привет, в четверг на канале вышел небольшой пост про контекстные менеджеры. Сейчас разберём, как их можно реализовать.

В любом контекстном менеджере должны быть определены методы __enter__ и __exit__. В качестве примера создадим подобие уже существующего open.

Метод __enter__ вызывается автоматически и возвращает объект файла. После того, как блок with заканчивается, также вызывается метод __exit__, который закрывает файл.

А более подробно мы рассказываем про эту тему в нашем курсе по продвинутым темам.

BY Python Academy




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

View MORE
Open in Telegram


Python Academy Telegram | DID YOU KNOW?

Date: |

China’s stock markets are some of the largest in the world, with total market capitalization reaching RMB 79 trillion (US$12.2 trillion) in 2020. China’s stock markets are seen as a crucial tool for driving economic growth, in particular for financing the country’s rapidly growing high-tech sectors.Although traditionally closed off to overseas investors, China’s financial markets have gradually been loosening restrictions over the past couple of decades. At the same time, reforms have sought to make it easier for Chinese companies to list on onshore stock exchanges, and new programs have been launched in attempts to lure some of China’s most coveted overseas-listed companies back to the country.

How Does Bitcoin Mining Work?

Bitcoin mining is the process of adding new transactions to the Bitcoin blockchain. It’s a tough job. People who choose to mine Bitcoin use a process called proof of work, deploying computers in a race to solve mathematical puzzles that verify transactions.To entice miners to keep racing to solve the puzzles and support the overall system, the Bitcoin code rewards miners with new Bitcoins. “This is how new coins are created” and new transactions are added to the blockchain, says Okoro.

Python Academy from kr


Telegram Python Academy
FROM USA