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

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

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

    any plans to make pprint() a builtin?

    John Salerno, May 14, 2006, in forum: Python
    Replies:
    9
    Views:
    311
    Edward Elliott
    May 17, 2006
  2. Brian L. Troutwine
    Replies:
    6
    Views:
    318
    Adam Jones
    Sep 20, 2006
  3. Jorge Vargas
    Replies:
    0
    Views:
    267
    Jorge Vargas
    Feb 25, 2008
  4. Gabriel Genellina
    Replies:
    0
    Views:
    502
    Gabriel Genellina
    Feb 26, 2008
  5. Paddy
    Replies:
    0
    Views:
    297
    Paddy
    Apr 9, 2008
Loading...

Share This Page