'pretty print' for built in types

R

Robert Dailey

Hi,

Is there a built in way to 'pretty print' a dict, list, and tuple
(Amongst other types)? Dicts probably print the ugliest of them all,
and it would be nice to see a way to print them in a readable way. I
can come up with my own function to do this, but I don't want to do
this if I don't have to.
 
E

eric

Hi,

Is there a built in way to 'pretty print' a dict, list, and tuple
(Amongst other types)? Dicts probably print the ugliest of them all,
and it would be nice to see a way to print them in a readable way. I
can come up with my own function to do this, but I don't want to do
this if I don't have to.


you can have a look at [http://code.google.com/p/prynt/ prynt], it
provides some simple functions, to pretty print into RestructuredText,
and then, when the process is finished (it's an option) show the
'console' converted into html.
dict are transformed into definition:
key: value
key: value


it helps ?
 
A

aspersieman

Is there a built in way to 'pretty print' a dict, list, and tuple
(Amongst other types)? Dicts probably print the ugliest of them all,
and it would be nice to see a way to print them in a readable way. I
can come up with my own function to do this, but I don't want to do
this if I don't have to.

For lists use 'join'.
lista = ['a', 'b', 'c', 4]
','.join(lista)
a,b,c,4

For more info google 'python join' or see [1]

Regards

Nicol

[1] http://docs.python.org/library/stdtypes.html#string-methods
 
C

Chris Rebert

Hi,

Is there a built in way to 'pretty print' a dict, list, and tuple
(Amongst other types)? Dicts probably print the ugliest of them all,
and it would be nice to see a way to print them in a readable way. I
can come up with my own function to do this, but I don't want to do
this if I don't have to.

There's the `pprint` module in the std lib:
http://docs.python.org/library/pprint.html

Cheers,
Chris
[/QUOTE]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top