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: |

How to Use Bitcoin?

n the U.S. people generally use Bitcoin as an alternative investment, helping diversify a portfolio apart from stocks and bonds. You can also use Bitcoin to make purchases, but the number of vendors that accept the cryptocurrency is still limited. Big companies that accept Bitcoin include Overstock, AT&T and Twitch. You may also find that some small local retailers or certain websites take Bitcoin, but you’ll have to do some digging. That said, PayPal has announced that it will enable cryptocurrency as a funding source for purchases this year, financing purchases by automatically converting crypto holdings to fiat currency for users. “They have 346 million users and they’re connected to 26 million merchants,” says Spencer Montgomery, founder of Uinta Crypto Consulting. “It’s huge.”

For some time, Mr. Durov and a few dozen staffers had no fixed headquarters, but rather traveled the world, setting up shop in one city after another, he told the Journal in 2016. The company now has its operational base in Dubai, though it says it doesn’t keep servers there.Mr. Durov maintains a yearslong friendship from his VK days with actor and tech investor Jared Leto, with whom he shares an ascetic lifestyle that eschews meat and alcohol.

telegram from id


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