Pretty, ein prettyprinter

Stellt hier eure Projekte vor.
Internetseiten, Skripte, und alles andere bzgl. Python.
Antworten
mitsuhiko
User
Beiträge: 1790
Registriert: Donnerstag 28. Oktober 2004, 16:33
Wohnort: Graz, Steiermark - Österreich
Kontaktdaten:

pretty ist pprint nur erweiterbar. pretty.pretty(obj) entspricht pprint.pformat(obj), pretty.pprint(obj) entspricht pprint.pprint(obj). Wie man ihn erweitern kann steht im Modul Docstring.

Beispielausgabe:

Code: Alles auswählen

>>> import re
>>> from pretty import pprint
>>> class Foo(object):
...  def __init__(self):
...   self.foo = range(10)
...   self.bar = dict.fromkeys(zip("abcdefghijklmnopq", range(20)))
...   self.pattern = re.compile(r'<[^>]+>')
... 
>>> pprint(Foo())
<__main__.Foo at 0x5b16b0>
>>> pprint(Foo(), verbose=True)
<__main__.Foo at 0x5b1cf0
 bar={('l', 11): None,
      ('a', 0): None,
      ('b', 1): None,
      ('g', 6): None,
      ('n', 13): None,
      ('k', 10): None,
      ('e', 4): None,
      ('o', 14): None,
      ('q', 16): None,
      ('f', 5): None,
      ('m', 12): None,
      ('c', 2): None,
      ('j', 9): None,
      ('h', 7): None,
      ('p', 15): None,
      ('i', 8): None,
      ('d', 3): None},
 foo=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
 pattern=re.compile(r'<[^>]+>')>
TUFKAB – the user formerly known as blackbird
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

Yay, ich könnte das wohl auch nutzen um meinen AST einer Straightline-Programmiersprache wieder in Text zu wandeln :)
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
Antworten