如何漂亮地打印 f-Strings?

How to prettyprint f-Strings?

正在尝试从 f 字符串打印字典:

import pprint as pp

my_dict = {
    "key_a": ["here", "are", "the", "things"]
    , "key_b": ["that", "i", "want"]
    , "key_b": ["to", "share", "with", "the", "worlddddddddddddddddddddd"]
}

pp.pprint(f"Let's talk about all of these things:\n\n{my_dict}")

输出(不漂亮):

("Let's talk about all of these things:\n"
 '\n'
 "{'key_a': ['here', 'are', 'the', 'things'], 'key_b': ['to', 'share', 'with', "
 "'the', 'worlddddddddddddddddddddd']}")

有没有办法让这个在 f 弦中工作,所以我不必 pp.pprint(my_dict)

不是真的。最接近的做法是使用 pformat,即没有 print.

pprint
print(f"Let's talk about all of these things:\n\n{pp.pformat(my_dict)}")