Welcome, guest | Sign In | My Account | Store | Cart

Printing sequences or maps containing non-ASCII strings results in escape sequences. This function uses the not-so-commonly-known "string_escape" codec to facilitate printing such sequences for quick-viewing.

Python, 2 lines
def decoded_repr(obj):
    return repr(obj).decode("string_escape")

This is mainly used for quick debugging purposes. It will work for strings encoded in your environment's natural encoding, but it won't correctly show unicode characters that cannot be encoded in your natural encoding.

Created by Christos Georgiou on Fri, 12 Aug 2005 (PSF)
Python recipes (4591)
Christos Georgiou's recipes (6)

Required Modules

  • (none specified)

Other Information and Tasks