[PYTHON MATRIX-SIG] Printing arrays and repr vs. str

Jim Hugunin hugunin@mit.edu
Fri, 28 Feb 1997 14:38:06 -0500


PythonWin has just highlighted a critical flaw in the design of array 
printing for NumPy.

To explain: For C objects, there are three methods related to the string 
representation of an array.  One returns the str(a), one returns the 
repr(a), and the third one is used to print out the array directly.

Under the current design, str(a) and repr(a) both behave "properly" for 
python's design.  Unfortunately, the print method uses the str(a) 
representation, which according to Guido is  not the correct way to display 
python objects (and if anybody should know it's Guido ;-).

The interesting fact is that this "bug" in the print method has led to the 
behavior that almost all users of NumPy seem to want in their interactive 
work with arrays.

I am at a total loss as to how to fix this.  The right thing to do is to 
change the behavior of the print method to use the repr version of an 
array.  This will however make it much less enjoyable to work with arrays 
in an interpreter.  Not fixing the bug in the print method though will make 
NumPy inconsistent with the rest of python objects, and lead to 
inconsistent behavior as observed in PythonWin recently.

Does anybody have any good suggestions on this one?

-Jim


_______________
MATRIX-SIG  - SIG on Matrix Math for Python

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