Reputation: 11556
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?
Upvotes: 1
Views: 538
Reputation: 4746
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')
Upvotes: 1