Why did I get ModuleNotFoundError?

Question:

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?

import pprint.pprint as p
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-10-029262df2bb9> in <module>
----> 1 import pprint.pprint as p

ModuleNotFoundError: No module named 'pprint.pprint'; 'pprint' is not a package
Asked By: Rama

||

Answers:

Because there’s no module pprint.pprint, only a module pprint. You mean:

from pprint import pprint as p

(From the module pprint import the name pprint as p.)

Answered By: deceze
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.