Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't import pprint

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.

like image 333
Thrynn Avatar asked Aug 04 '15 19:08

Thrynn


People also ask

How do I enable Pprint in Python?

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() .

Is Pprint part of Python?

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.

What is Pprint Pprint ()?

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.

Could not find a version that satisfies the requirement Pprint?

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.


1 Answers

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.

like image 119
Robᵩ Avatar answered Sep 22 '22 00:09

Robᵩ