How do I make pprint do this

Discussion in 'Python' started by jcervidae, May 20, 2009.

  1. jcervidae

    jcervidae Guest

    I cannot get pprint to format output how I would like. pydb does. I
    tried grepping the source but still couldn't grok it. Here:

    (Pydb) a = range(1,100)
    (Pydb) pp a
    [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10, 11, 12, 13, 14, 15, 16, 17,
    18, 19, 20
    21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
    38, 39, 40
    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
    58, 59, 60
    61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
    78, 79...]

    It puts multiple elements on the same line. I can't work out how to
    make it do that.
     
    jcervidae, May 20, 2009
    #1
    1. Advertisements

  2. jcervidae

    Guest

    >> I cannot get pprint to format output how I would like. pydb does. I
    >> tried grepping the source but still couldn't grok it.


    That's not the way pprint works. You have no control over how it arranges
    its output. If you need something more flexible you'll have to roll your
    own.

    --
    Skip Montanaro - - http://www.smontanaro.net/
    America's vaunted "free press" notwithstanding, story ideas that expose
    the unseemly side of actual or potential advertisers tend to fall by the
    wayside. Not quite sure why. -- Jim Thornton
     
    , May 20, 2009
    #2
    1. Advertisements

  3. jcervidae

    Robert Kern Guest

    On 2009-05-20 10:37, wrote:
    > >> I cannot get pprint to format output how I would like. pydb does. I
    > >> tried grepping the source but still couldn't grok it.

    >
    > That's not the way pprint works. You have no control over how it arranges
    > its output. If you need something more flexible you'll have to roll your
    > own.


    Or use Armin Ronacher's excellent pretty.py:

    http://dev.pocoo.org/hg/sandbox/file/tip/pretty

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
     
    Robert Kern, May 20, 2009
    #3
    1. Advertisements

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. John Salerno

    any plans to make pprint() a builtin?

    John Salerno, May 14, 2006, in forum: Python
    Replies:
    9
    Views:
    407
    Edward Elliott
    May 17, 2006
  2. Brian L. Troutwine
    Replies:
    6
    Views:
    375
    Adam Jones
    Sep 20, 2006
  3. Mark Asbach
    Replies:
    1
    Views:
    670
    Leo Kislov
    Nov 3, 2006
  4. Jorge Vargas
    Replies:
    0
    Views:
    330
    Jorge Vargas
    Feb 25, 2008
  5. Paddy
    Replies:
    0
    Views:
    356
    Paddy
    Apr 9, 2008
  6. Donald 'Paddy' McCarthy

    pprint module and newer standard types

    Donald 'Paddy' McCarthy, Apr 18, 2008, in forum: Python
    Replies:
    0
    Views:
    323
    Donald 'Paddy' McCarthy
    Apr 18, 2008
  7. rh0dium
    Replies:
    1
    Views:
    255
    Paul McGuire
    Nov 7, 2008
  8. Peng Yu
    Replies:
    0
    Views:
    177
    Peng Yu
    Mar 17, 2013
Loading...