Reputation: 13
I try to use pprint to print a list:
>>> import pprint
>>> a = [1, 3, 6, 8, 0]
>>> pprint.pprint(a)
[1, 3, 6, 8, 0]
>>>
why not this
[1,
3,
6,
8,
0]
look forward you answer! THANKS!
Upvotes: 0
Views: 482
Reputation: 310
you can use width parameter:
pp = pprint.PrettyPrinter(width=4)
pp.pprint(a)
Upvotes: 0
Reputation: 377
According to the official documentation, it appears that you need to specifiy the width
of your input which is set to 80
by default. You may try the following
>>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
>>> pp = pprint.PrettyPrinter(indent=4, width=50)
>>> pp.pprint(stuff)
['spam', 'eggs', 'lumberjack', 'knights', 'ni']
>>> pp = pprint.PrettyPrinter(indent=4, width=1)
>>> pp.pprint(stuff)
[ 'spam',
'eggs',
'lumberjack',
'knights',
'ni']
>>>
Upvotes: 2