prettier

Generalized pretty print based on Wadler's paper
Download

prettier Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Python License
  • Publisher Name:
  • NISHIO Hirokazu
  • Publisher web site:
  • http://bitbucket.org/nishio/

prettier Tags


prettier Description

Generalized pretty print based on Wadler's paper MotivationPython'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.prettier is a Python library is an implementation in Python of "A prettier print" introduced by Philip Wadler.http://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdfThe algorithm was also implemented in Ruby's standard library: prettyprint.rb.http://ruby-doc.org/stdlib/libdoc/prettyprint/rdoc/classes/PrettyPrint.htmlExample: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 = # fill given space>>> print(pretty(40, fill(docs)))1. abc 2. abc 3. abc>>> print(pretty(13, fill(docs)))1. abc 2. abc3. abc>>> print(pretty(8, fill(docs)))1. abc2. abc3. abc# horizontal only>>> print(pretty(1, spread(docs)))1. abc 2. abc 3. abc# vertical only>>> print(pretty(100, stack(docs)))1. abc2. abc3. 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. abc2. abc3. 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. abcSetup:easy_install prettierUsage:Read the doctest please. Requirements: · Python


prettier Related Software