Skip to main content
100%

[print_unicode] python2 下在命令行中正常打印嵌套在 dict/list 内的 unicode 字符 #python #string

✓ Published0🌍 Public
SShawn91
Last edited Jul 8, 2019
Created on Nov 29, 2018

This example shows a Python 2 utility function that makes nested Unicode characters inside dictionaries and lists print correctly to the command line. The function `print_uni` takes any string `s`, applies `repr` to capture its escaped form, and then decodes that representation using `"unicode-escape"` to reveal the actual Unicode glyphs. It relies on the built-in `repr` function and the string `decode` method, demonstrating a workaround for Python 2’s default ASCII-based printing of container structures. The code is a standalone snippet from a gist by Shawn91, focusing on a common debugging pain point.

AI-generated description

Similar vizzes