[Tutor] Is there any standard module for "pretty printing" to stdout?

Gerrit Holl gerrit at nl.linux.org
Wed Dec 10 14:37:44 EST 2003


Branimir Petrovic wrote:
> Subject: [Tutor] Is there any standard module for "pretty printing" to stdout?

There is indeed - it is called: pprint, after prettyprint. It does
exactly what you want:

20:37:11:232:5  >>> pprint.pprint(dict(locals()))
{'PROMPT':
'%(pre)s\x1b[01;40;32m%(time)s:\x1b[36m%(vers)s:\x1b[31m%(count)-2s\x1b[00m%(post)s',
 'Prompt': <class '__main__.Prompt'>,
 '__builtins__': <module '__builtin__' (built-in)>,
 '__doc__': None,
 '__file__': '/home/gerrit/.pythonrc',
 '__name__': '__main__',
 'datetime': <module 'datetime' from
'/usr/local/lib/python2.3/lib-dynload/datetime.so'>,
 'division': _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0),
8192),
 'pprint': <module 'pprint' from '/usr/local/lib/python2.3/pprint.pyc'>,
 'readline': <module 'readline' from
'/usr/local/lib/python2.3/lib-dynload/readline.so'>,
 'rlcompleter': <module 'rlcompleter' from
'/usr/local/lib/python2.3/rlcompleter.pyc'>,
 'sys': <module 'sys' (built-in)>}

It is documented at:
http://www.python.org/dev/doc/devel/lib/module-pprint.html

yours,
Gerrit.

-- 
249. If any one hire an ox, and God strike it that it die, the man who
hired it shall swear by God and be considered guiltless.
          -- 1780 BC, Hammurabi, Code of Law
-- 
Asperger's Syndrome - a personal approach:
	http://people.nl.linux.org/~gerrit/english/



More information about the Tutor mailing list