[newbie]Is there a module for print object in a readable format?

Micah Elliott mde at micah.elliott.name
Wed Oct 19 17:32:15 CEST 2005


On Oct 20, Steven D'Aprano wrote:
> That's not what I get. What are you using?
> 
> py> pprint.pprint([1,2,3,4,[0,1,2], 5], width=1, indent=4)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: pprint() got an unexpected keyword argument 'width'

I find it useful to have all relevant python versions (as listed on
http://www.python.org/download/) installed on my primary test
machines.  It really helps me with portability testing:

   $ ls /usr/local/bin/python*
   /usr/local/bin/python
   /usr/local/bin/python2.0
   /usr/local/bin/python2.1
   /usr/local/bin/python2.2
   /usr/local/bin/python2.3
   /usr/local/bin/python2.4

Then I see that v2.3 didn't have 'width':

   $ python2.3 -c 'import pprint; pprint.pprint([1,2,3,4,[0,1,2], 5],
   width=1, indent=4)'
   Traceback (most recent call last):
     File "<string>", line 1, in ?
     TypeError: pprint() got an unexpected keyword argument 'width'

But v2.4 does:

   $ python2.4 -c 'import pprint; pprint.pprint([1,2,3,4,[0,1,2], 5],
   width=1, indent=4)'
   [   1,
       2,
       3,
       4,
       [   0,
           1,
           2],
       5]

-- 
_  _     ___
|\/|icah |- lliott  http://micah.elliott.name  mde at micah.elliott.name
"  "     """



More information about the Python-list mailing list