as an alternative to the "pprint" module

Youngjae·2020년 9월 24일

Python

목록 보기
7/8
import json

# The standard string repr for dicts is hard to read:
my_mapping = {'a': 23, 'b': 42, 'c': 0xc0ffee}
print(f"{my_mapping=}")

# The "json" module can do a much better job:
print(json.dumps(my_mapping, indent=4, sort_keys=True))

execution

my_mapping={'a': 23, 'b': 42, 'c': 12648430}
{
    "a": 23,
    "b": 42,
    "c": 12648430
}

ref
https://realpython.com

profile
Eighty percent of success is showing up.

0개의 댓글