简体   繁体   English

在不使用unicode的情况下打印python dict

[英]Printing a python dict without the unicode

I have a dictionary of strings I need to print to my terminal for debugging a regex. 我有一个字符串字典,需要打印到终端上以调试正则表达式。 It's printing as character code spew instead of something readable: 它以字符代码喷出而不是可读的方式打印:

{'\x00F\x00a\x00c\x00e\x00b\x00o\x00o\x00k\x00 \x00/\x00 \x00T\x00w\x00i\x00t\x00t\x00e\x00r\x00':
 '\x00F\x00a\x00c\x00e\x00b\x00o\x00o\x00k\x00 \x00/\x00 \x00T\x00w\x00i\x00t\x00t\x00e\x00r\x00'}

How can print the dict as something readable? 如何将字典打印为可读的?

Try this: 尝试这个:

d = {'\x00F\x00a\x00c\x00e\x00b\x00o\x00o\x00k\x00 \x00/\x00 \x00T\x00w\x00i\x00t\x00t\x00e\x00r\x00':
 '\x00F\x00a\x00c\x00e\x00b\x00o\x00o\x00k\x00 \x00/\x00 \x00T\x00w\x00i\x00t\x00t\x00e\x00r\x00'}

for key, value in d.items():
    print (key+" : "+value).decode('utf-8')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM