Programming newbie here. Whenever I attempt to 'import pprint' in the Python IDLE, I get the following error:
>>> import pprint
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
import pprint
File "C:\Python34\pprint.py", line 10, in <module>
pprint(count)
NameError: name 'pprint' is not defined
Thought I would try to 'pip install pprint' in command line but that didn't work either:
PS C:\Python34> pip install pprint
Collecting pprint
Could not find a version that satisfies the requirement pprint (from versions: )
No matching distribution found for pprint
I thought Python 3.4.3 was supposed to come with pprint module. How do I get it to work? Can't seem to import pprint but all other modules are working fine. I need the pprint module to work for completion of some exercises from Automate The Boring Stuff with Python. Thanks for looking at my question.
To use pprint, begin by importing the library at the top of your Python file. From here you can either use the . pprint() method or instantiate your own pprint object with PrettyPrinter() .
The pprint module in Python is a utility module that you can use to print data structures in a readable, pretty way. It's a part of the standard library that's especially useful for debugging code dealing with API requests, large JSON files, and data in general.
The pprint module provides a capability to “pretty-print” arbitrary Python data structures in a form which can be used as input to the interpreter. If the formatted structures include objects which are not fundamental Python types, the representation may not be loadable.
The error "Could not find a version that satisfies the requirement pprint" occurs when we try to pip install the pprint module. To solve the error, import the module directly and run your script as pprint is a built-in Python module.
You've named a program pprint
. Rename your program to something other than pprint.py
and remove any pprint.pyc
file that might be present.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With