Telegram Group & Telegram Channel
🧵 Как упростить отладку Python-скриптов с помощью breakpoint()

Привет! Сегодня хочу поделиться небольшим, но очень полезным трюком, который многие почему-то упускают — встроенная функция breakpoint().

С версии Python 3.7 и выше ты можешь просто вставить breakpoint() в нужное место кода, и он сразу остановится, запустив интерактивный отладчик. По умолчанию это pdb, но можно переопределить через переменную окружения PYTHONBREAKPOINT.

Пример:


def calculate(x, y):
result = x * y
breakpoint()
return result + 1

calculate(3, 5)


В момент вызова breakpoint() ты окажешься прямо в интерактивной сессии: можно смотреть переменные, шагать по коду и т.д.

🔥 Почему это удобно:

* Не нужно импортировать pdb вручную
* Работает в любом месте — в скриптах, Django-представлениях, Flask-хендлерах
* Легко отключается: запусти скрипт с PYTHONBREAKPOINT=0, и breakpoint() будет просто игнорироваться

Пользуетесь ли вы этой фичей в повседневной работе? Или все еще вставляете print()? 😄

Подписывайтесь на канал 👉@pythonofff



tg-me.com/pythonofff/2912
Create:
Last Update:

🧵 Как упростить отладку Python-скриптов с помощью breakpoint()

Привет! Сегодня хочу поделиться небольшим, но очень полезным трюком, который многие почему-то упускают — встроенная функция breakpoint().

С версии Python 3.7 и выше ты можешь просто вставить breakpoint() в нужное место кода, и он сразу остановится, запустив интерактивный отладчик. По умолчанию это pdb, но можно переопределить через переменную окружения PYTHONBREAKPOINT.

Пример:


def calculate(x, y):
result = x * y
breakpoint()
return result + 1

calculate(3, 5)


В момент вызова breakpoint() ты окажешься прямо в интерактивной сессии: можно смотреть переменные, шагать по коду и т.д.

🔥 Почему это удобно:

* Не нужно импортировать pdb вручную
* Работает в любом месте — в скриптах, Django-представлениях, Flask-хендлерах
* Легко отключается: запусти скрипт с PYTHONBREAKPOINT=0, и breakpoint() будет просто игнорироваться

Пользуетесь ли вы этой фичей в повседневной работе? Или все еще вставляете print()? 😄

Подписывайтесь на канал 👉@pythonofff

BY Python академия




Share with your friend now:
tg-me.com/pythonofff/2912

View MORE
Open in Telegram


telegram Telegram | DID YOU KNOW?

Date: |

Look for Channels Online

You guessed it – the internet is your friend. A good place to start looking for Telegram channels is Reddit. This is one of the biggest sites on the internet, with millions of communities, including those from Telegram.Then, you can search one of the many dedicated websites for Telegram channel searching. One of them is telegram-group.com. This website has many categories and a really simple user interface. Another great site is telegram channels.me. It has even more channels than the previous one, and an even better user experience.These are just some of the many available websites. You can look them up online if you’re not satisfied with these two. All of these sites list only public channels. If you want to join a private channel, you’ll have to ask one of its members to invite you.

Telegram hopes to raise $1bn with a convertible bond private placement

The super secure UAE-based Telegram messenger service, developed by Russian-born software icon Pavel Durov, is looking to raise $1bn through a bond placement to a limited number of investors from Russia, Europe, Asia and the Middle East, the Kommersant daily reported citing unnamed sources on February 18, 2021.The issue reportedly comprises exchange bonds that could be converted into equity in the messaging service that is currently 100% owned by Durov and his brother Nikolai.Kommersant reports that the price of the conversion would be at a 10% discount to a potential IPO should it happen within five years.The minimum bond placement is said to be set at $50mn, but could be lowered to $10mn. Five-year bonds could carry an annual coupon of 7-8%.

telegram from nl


Telegram Python академия
FROM USA