[PYTHON MATRIX-SIG] New pretty printer

Guido van Rossum guido@CNRI.Reston.VA.US
Fri, 02 Feb 1996 19:06:42 -0500


> My pretty printer has made some progress, and I'll include the latest
> version below. Just put it into your copy of Numeric.py. Line wrapping
> is still missing. (BTW, what would be a good default line width? In the
> VT100 days that would have been 80 characters, but does this still
> make sense?)

Yes!  I'd even say 77, so at least one level of email quoting won't
cause it to wrap.  I keep my Emacs religiously at 80 columns wide when
programming -- this way I can fit two columns of windows plus some
icons on my screen.  Also, the default wrap columns for printing text
seems to be 80 still.

> I can't say that I am satisfied with float formatting,
> but anything better than now will be difficult to do and, most of
> all, slow. The two problems are
> 
> 1) Trailing zeros in non-exponential format. Right now there are
>    always eight digits after the decimal point. It would be better
>    to replace trailing zeros by spaces (easy) and reduce the width
>    of the output fields to match the longest remaining number.
>    But that requires a scan of the string representations of all
>    the elements in an array, which is an expensive operation.
> 
> 2) In exponential notation, numbers with three-digit exponents will
>    not line up correctly with others. It would be necessary to
>    have three-digit exponents for all numbers when at least
>    one element requires it, but there is no formatting option
>    to specify the number of exponent digits. The only solution
>    would be cosmetic surgery on the final string, but that again
>    is slow.

(For both case:) Surely, if you're printing a reasonably sized array,
it will be fast enough, and if it is truly huge, nobody will really
look at the numbers...  I'd say make it look as good as you can.
Also, perhaps a regular expression can help you do the cosmetic
surgery efficiently.

--Guido van Rossum <guido@CNRI.Reston.VA.US>
URL: <http://www.python.org/~guido/>

=================
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================