"TypeError: 'module' object is not callable" trying to use pprint
Question:
I’ve tried this code to pretty print a dict
:
import pprint
pprint({})
This throws the following error:
Traceback (most recent call last):
File "temp.py", line 3, in <module>
pprint({})
TypeError: 'module' object is not callable
Why is it not callable?
Answers:
Try importing using:
from pprint import pprint
The pprint()
function is in the pprint
module.
you need to use the module name when calling.
import pprint
pprint.pprint(...)
Or you can import a specific method.
from pprint import pprint
pprint(...)
I’ve tried this code to pretty print a dict
:
import pprint
pprint({})
This throws the following error:
Traceback (most recent call last):
File "temp.py", line 3, in <module>
pprint({})
TypeError: 'module' object is not callable
Why is it not callable?
Try importing using:
from pprint import pprint
The pprint()
function is in the pprint
module.
you need to use the module name when calling.
import pprint
pprint.pprint(...)
Or you can import a specific method.
from pprint import pprint
pprint(...)