Why does not pprint work?

Chris Angelico rosuav at gmail.com
Tue Jul 22 18:19:45 EDT 2014


On Wed, Jul 23, 2014 at 8:05 AM, fl <rxjwg98 at gmail.com> wrote:
> On Tuesday, July 22, 2014 5:51:07 PM UTC-4, emile wrote:
>> On 07/22/2014 02:42 PM, fl wrote:
>> pprint is a module name -- you need to invoke the pprint function from
>> within the pprint module:
>> pprint.pprint(board)
>
> Thanks. I am curious about the two pprint. Is it the first pprint the name of the
> module? The second pprint is the function name?

Correct. There's a module pprint which provides a function
pprint.pprint. It's like you can do this:
>>> import math
>>> math.sin(3.14/2)
0.9999996829318346

Or this:
>>> from math import sin
>>> sin(3.14/2)
0.9999996829318346

It's just that in this case, "math" and "sin" are both "pprint".

> Then, how can I list all the function of pprint?

>>> import pprint
>>> help(pprint)

> And, is there a way to list the variables I create in Python?

Kinda. Try this:

>>> dir()

There'll be some in there that you didn't make, but that's a start.
You could also try vars() or globals(), which will give you their
values as well.

ChrisA



More information about the Python-list mailing list