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?
JavaScript
x
2
1
import pprint.pprint as p
2
JavaScript
1
7
1
---------------------------------------------------------------------------
2
ModuleNotFoundError Traceback (most recent call last)
3
<ipython-input-10-029262df2bb9> in <module>
4
----> 1 import pprint.pprint as p
5
6
ModuleNotFoundError: No module named 'pprint.pprint'; 'pprint' is not a package
7
Advertisement
Answer
Because there’s no module pprint.pprint
, only a module pprint
. You mean:
JavaScript
1
2
1
from pprint import pprint as p
2
(From the module pprint
import the name pprint
as p
.)