'pretty print' for built in types

Discussion in 'Python' started by Robert Dailey, Dec 9, 2008.

  1. 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.
     
    Robert Dailey, Dec 9, 2008
    #1
    1. Advertising

  2. Robert Dailey

    eric Guest

    On Dec 9, 4:31 pm, Robert Dailey <> wrote:
    > 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 ?
     
    eric, Dec 9, 2008
    #2
    1. Advertising

  3. Robert Dailey

    aspersieman Guest

    On Tue, 09 Dec 2008 17:31:41 +0200, Robert Dailey <> wrote:

    >
    > 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

    --

    Christopher Columbus was, after all, a super intelligent hypersquirrel from the planet Klepton. How else could he have known where to find america?
     
    aspersieman, Dec 9, 2008
    #3
  4. Robert Dailey

    Chris Rebert Guest

    On Tue, Dec 9, 2008 at 7:31 AM, Robert Dailey <> wrote:
    > 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

    --
    Follow the path of the Iguana...
    http://rebertia.com

    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
     
    Chris Rebert, Dec 9, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Montgomery
    Replies:
    0
    Views:
    633
    Andrew Montgomery
    Sep 17, 2003
  2. Alan G Isaac

    pretty print 2D arrays

    Alan G Isaac, Aug 12, 2004, in forum: Python
    Replies:
    1
    Views:
    564
    Colin J. Williams
    Aug 13, 2004
  3. John Hunter
    Replies:
    5
    Views:
    670
    Paul McNett
    Sep 28, 2004
  4. Alona
    Replies:
    2
    Views:
    658
  5. Grant Edwards
    Replies:
    0
    Views:
    200
    Grant Edwards
    Oct 25, 2011
Loading...

Share This Page