"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?

Asked By: user5760871

||

Answers:

Try importing using:

from pprint import pprint

The pprint() function is in the pprint module.

Answered By: Jamie Bull

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(...)
Answered By: Rajarshi Das
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.