Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

generalized pretty print based on Wadler's paper

Project description

Motivation

Python’s standard pretty print library (pprint) doesn’t support user defined class. Once I wanted to print Python’s AST prettier, however it’s not possible to use “pprint” for the purpose.

What is it?

This library is an implementation in Python of “A prettier print” introduced by Philip Wadler.

http://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf

The algorithm was also implemented in Ruby’s standard library: prettyprint.rb.

http://ruby-doc.org/stdlib/libdoc/prettyprint/rdoc/classes/PrettyPrint.html

Example

The purpose of this library is to give prettyprint ability on your class. In examples/show_ast.py you can see such examples. Here are small samples.

>>> from prettier import *
>>> docs = [Text("1. abc"), Text("2. abc"), Text("3. abc")]

# fill given space
>>> print(pretty(40, fill(docs)))
1. abc 2. abc 3. abc

>>> print(pretty(13, fill(docs)))
1. abc 2. abc
3. abc

>>> print(pretty(8, fill(docs)))
1. abc
2. abc
3. abc

# horizontal only
>>> print(pretty(1, spread(docs)))
1. abc 2. abc 3. abc

# vertical only
>>> print(pretty(100, stack(docs)))
1. abc
2. abc
3. abc

# when there isn't enough space to put horizontal, put vertical
>>> print(pretty(20, stack_or_spread(docs)))
1. abc 2. abc 3. abc

>>> print(pretty(13, stack_or_spread(docs)))
1. abc
2. abc
3. abc

# when there isn't enough space to put horizontal, use indent
>>> print(pretty(10, can_break_with_nest(docs)))
1. abc
  2. abc
  3. abc

Setup

$ easy_install prettier

Usage

Read the doctest please.

History

0.92 (2010-09-02)

  • Relative file(“README.rst”) fail on PyPI server. Fixed the bug in setup.py.
  • Because I didn’t write MANIFEST.in, README.rst wasn’t included in source distribution. Add it.
  • PEP8 discouraged underscores in module name. Renamed it.

0.91 (2010-09-02)

  • Because I did $ python setup.py sdist bdist bdist_egg upload, there comes “dumb” binary. Removed bdist.

0.9 (2010-09-02)

  • first release

Roadmap

  • Make a function pprint(obj) which work like standard pprint.pprint

When the goal is achived the version goes 1.0.

For developer(include me)

Here is the repository: https://bitbucket.org/nishio/prettierprint

Don’t forget to run test and confirm tests cover all code:

$ coverage run prettier/__init__.py && coverage html

Don’t forget to test README.rst is valid:

$ rst2html.py README.rst > README.html

When you relaese new version, don’t put bdist option.:

$ python setup.py sdist bdist_egg upload

Lisence

Same as Python 3.0.

Acknowleagement

  • Takayuki SHIMIZUKAWA <shimizukawa at gmail com>
  • Atsushi Odagiri <aodagx at gmail com>
  • yutaka matsubara <yutaka matsubara at gmail com>

Contact

NISHIO Hirokazu <nishio (dot) hirokazu (at) gmail (dot) com>

Project details


Release history Release notifications

This version
History Node

0.92

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
prettier-0.92-py2.6.egg (17.6 kB) Copy SHA256 hash SHA256 Egg 2.6 Sep 2, 2010
prettier-0.92.tar.gz (6.0 kB) Copy SHA256 hash SHA256 Source None Sep 2, 2010

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page