Skip to content
Advertisement

Tag: pprint

Why did I get ModuleNotFoundError?

I tried the following code to import pprint from pprint module like import matplotlib.pyplot as plt. But I got an error instead. Why did I get this error? Answer Because there’s no module pprint.pprint, only a module pprint. You mean: (From the module pprint import the name pprint as p.)

Disabling sorting mechanism in pprint output

I have big dictionary which I`m printing for viewing with prettyprint, but how I can keep formatting but kill sorting mechanism in pprint? Answer Python 3.8 or newer: Use sort_dicts=False: Python 3.7 or older: You can monkey patch the pprint module. Since the 2nd output is essentiallly randomly sorted, your output may be different from mine: Another version that is

Advertisement