ActivePython word wrap in Shell or PythonWin during list printout

Nick Perkins nperkins7 at home.com
Thu Jul 12 00:30:14 CEST 2001


module pprint does a nice job.

I use it like this:
from pprint import pprint as pp

>>> pp(dir())  ...etc



"Rufus V. Smith" <nospam at nospam> wrote in message
news:3b4cc843$0$172 at wodc7nh6.news.uu.net...
> I am running the latest Python from ActiveState and I have a
> problem that when I print a long list (Like dir()), the entire list
> prints out on one line and I have to scroll over to read it.
>
> Is there an environment setting to force word wrap at
> a certain line length?
>
> Or is there a list function that can take a list and
> pretty print it with word wrap.
>
> (Not having one gave me an opportunity to learn
> some  Python scripting as I wrote my own, but
> if there was a library standard, that might be better. )
>
>
> def marginprint(L,margin=80):
>      b=""
>      for a in L:
>          if len(str(a)+b)+3 >= margin :
>                 print b
>                 b = "'"+str(a)+"'"
>          else:
>                 if b: b+=","
>                 b += "'"+str(a)+"'"
>      if b: print b
>      b=""
>
>
> With this function, I just type marginprint(dir())
> and it will respect the margins.
>
> Only I have to load this into my environment every time
> I bring it up.
>
>
>
>
>
>
>





More information about the Python-list mailing list