On Sat, Feb 13, 2010 at 8:32 PM, Charles R Harris wrote:

On Sat, Feb 13, 2010 at 8:02 PM, Fernando Perez wrote:
On Sat, Feb 13, 2010 at 12:24 PM, Charles R Harris
>> One minor suggestion:  I think it would be useful to have the new
>> polys have some form of pretty-printing like the old ones.  It is
>> actually useful when working, to verify what one has at hand, to see
>> an expanded printout like the old ones do:
>>
>
> I thought about that, but decided it was best left to a derived class, say
> PrettyPoly ;) Overriding __repr__ and __str__ is an example where
> inheritance makes sense.

I disagree, I think one of the advantages of having both str and repr
is precisely to make it easy to have both a terse,
implementation-oriented representation and a more human-friendly one

Note that ipython calls __repr__ to print the output. __repr__ is supposed to provide a string that can be used to recreate the object, a pretty printed version of __repr__ doesn't provide that. Also, an array or list of polynomials, having pretty printed entries looks pretty ugly with the newlines and all -- try it with Poly1d. I was also thinking that someone might want to provide a better display at some point, drawing on a canvas, for instance. And what happens when the degree gets up over 100, which is quite reasonable with the Cheybshev polynomials?

Example:

>>> a
array([   2
1 x + 2 x + 3,    2
1 x + 2 x + 3,    2
1 x + 2 x + 3,
2
1 x + 2 x + 3,    2
1 x + 2 x + 3,    2
1 x + 2 x + 3,
2
1 x + 2 x + 3,    2
1 x + 2 x + 3,    2
1 x + 2 x + 3,
2
1 x + 2 x + 3], dtype=object)
>>> print a
[   2
1 x + 2 x + 3    2
1 x + 2 x + 3    2
1 x + 2 x + 3
2
1 x + 2 x + 3    2
1 x + 2 x + 3    2
1 x + 2 x + 3
2
1 x + 2 x + 3    2
1 x + 2 x + 3    2
1 x + 2 x + 3
2
1 x + 2 x + 3]

Chuck