[PYTHON MATRIX-SIG] RE: [PYTHONWIN-SIG] The difference between repr and str, and printing arrays

Michael McLay mclay@nist.gov
Wed, 12 Mar 1997 02:27:23 -0500


 > Generally I think the echo in the interpreter should endeavor to
 > give a value 
 > which if typed back in at the prompt will generate an "equivalent" value, 
 > ie, the __repr__.
 > 
 > array([ [ [ 1, 1, 1 ], [ 2, 2, 1 ] ],  [ [11, 11, 11],  [ [22, 22, 22] ] ] )
 > 
 > I understand that for arrays you might want something more human-readable, 
 > like
 > 
 >    1 1 1
 >    2 2 2
 >  
 >    11 11 11
 >    22 22 22
 > 
 > or whatever, but this, obviously, is not a __repr__ (or a __repr__ "punt" like
 > <open file "blah" at 0x5643ee>)... I actually use the echo quite a lot to 
 > generate
 > constant values to paste into programs...

I agree with Aaron.  This is the expected behavior within Python.
Being inconsistant with Matlab user expectations isn't a good reason
to break consistancy with the Python language.  The pretty print
version is readily available by using the print statement, so the more
human readable version is also readily available.

 > 
 > A compromise position might use a "formatted __repr__" for arrays, ie like
 > 
 > array(
 > [ [ [ 1, 1, 1 ],
 >     [ 2, 2, 1 ] ],
 > 
 >   [ [11, 11, 11], 
 >   [ [22, 22, 22] ] ] )
 > 

This is what Jim had planned on doing, but somehow the NT "bug fix" ended
up reversing the use of __str__ and __repr__ in the interactive echo
and the print statement. 


_______________
MATRIX-SIG  - SIG on Matrix Math for Python

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