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
Advertisement
Answer
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
.)