---
slug: "python-how-to-erase-printed-text"
title: "Python で、ターミナルに文字を出力してから消す"
description: "ESP32 開発ボード ( HW-394 / WROOM-32 ) に CircuitPython を書き込んで Python で I/O 制御する手順。bootloader モードと REPL 接続まで。"
url: "https://www.ytyng.com/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: "ja"
---

# Python で、ターミナルに文字を出力してから消す

シーケンス \b のバックスペースで、プリントした文字を消すことができる。


```python
print('requesting...', end='', flush=True)

heavy_method(...)...

print('\b' * 13, end='', flush=True)
```


コンテキストマネージャーで書くと

```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(...)

```
