Dev Helpers

Python / Unicode and formatting

Create a literal representation with ascii

Dev Helpers · December 20, 2025

ascii gives diagnostic text an ASCII-only representation. Escapes in the result describe the characters and do not change the source string.

Worked example

print(ascii('café'))

Result

'caf\xe9'

Implementation notes

A representation intended for a log is rarely appropriate for a customer label. Store the original value and apply escaping only in the diagnostic output.

Try it yourself

Compare print(value), repr(value) and ascii(value) for an accented label.

Open the Python example →

Editorial date December 20, 2025 · Published December 6, 2026

Related articles

Run an async function

An async function call creates a coroutine. A top-level runner supplies the event loop that executes it.

Transpose a matrix

Transposing rows into columns assumes a decision about uneven rows. Ordinary zip stops at the shortest input.

Unpack with a remainder

Starred unpacking separates a fixed header from a variable-length tail. It still requires enough elements for the fixed positions.