---
slug: "python-how-to-erase-printed-text"
title: "Output and Clear Text in Terminal with Python"
description: "Flash CircuitPython onto an ESP32 dev board (HW-394 / WROOM-32) and drive I/O in Python — bootloader mode and REPL connection."
url: "https://www.ytyng.com/en/blog/python-how-to-erase-printed-text"
publish_date: "2023-01-03T02:21:35Z"
created: "2023-01-03T02:21:35Z"
updated: "2026-05-11T13:21:40.267Z"
categories: ["Python"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20250605/fe0cd8e9e99f4f1e971f2fcb7eedb67c.png.webp?width=768"
has_video: true
has_music: true
video_urls: ["https://media.ytyng.net/ytyng-blog/268/featured-video-1.mp4", "https://media.ytyng.net/ytyng-blog/268/featured-video-2.mp4", "https://media.ytyng.net/ytyng-blog/268/featured-video-3.mp4"]
music_urls: ["https://media.ytyng.net/ytyng-blog/268/featured-music-268-2.mp3?v=3", "https://media.ytyng.net/ytyng-blog/268/featured-music-268-3.mp3"]
lang: "en"
---

# Output and Clear Text in Terminal with Python

With the backspace sequence `\b`, you can erase printed characters.

```python
print('requesting...', end='', flush=True)

heavy_method(...)...

print('\b' * 13, end='', flush=True)
```

When written with a context manager:

```python
import contextlib


@contextlib.contextmanager
def print_and_erase(text):
    print(text, end='', flush=True)
    yield
    print('\b' * len(text), end='', flush=True)


with print_and_erase('requesting...'):
    heavy_method(...)
```
