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

aaron watters aaron_watters@msn.com
Wed, 12 Mar 97 01:45:10 UT


Okay, just got this in my local mail (dunno where it got stuck) so I comment
again (but just to the matrix sig this time).

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...

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] ] ] )

(if I got the parens right, not using emacs here...)  This would both format 
the
data so a human could see the structure and such that Python could read it 
back
in.  One *could* argue that it actually is more easy to see the structure this 
way,
but I'm not going to do that!  I refuse!   -- Aaron Watters

[of course I violate my own imperatives, abusing __repr__ in IPwP, but
nevermind.]

_______________
MATRIX-SIG  - SIG on Matrix Math for Python

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