Using breakpoint() in Python3

Use Python’s breakpoint() function to easily step through your code.

The breakpoint() function was added in Python 3.7 and is part of Python’s built-in functions.

Using breakpoint() is as simple as adding it to your script and running the script.

Here is a simple example using flask.

from flask import Flask

app = Flask(__name__)

def index():
    return "Hello, breakpoint()!"

After starting the flask application, your terminal will be in a pdb instance and you can start debugging. Use the continue command to break out of the debugger and let the code continue executing. Use next to step to the next line of code.


Python 3 Virtual Environment Tips

Tips for creating and using virtual environments in Python 3.

Create a virtual environment

Create a virtual environment with the current Python3 version.

python3 -m venv <directory>

This will create a virtual environment for the given directory.


python3 -m venv venv
Activate a virtual environment

If you created a virtual environment from the Create a virtual environment snippet, you can activate a virtual environment for the created virtual environment directory.

source <virtual_environment_directory>/bin/activate


source venv/bin/activate
Deactivate a virtual environment

Use the deactivate command to exit the virtual environment.