[Tutor] method to print in interpreter

Christopher Smith csmith@blakeschool.org
Thu, 21 Jun 2001 17:47:49 -0500


Dear List,

I read about defining __str__ in a class so the interpreter will know how 
to process a print command but I have not yet found what I must do to be 
able to get it to print if, in the interpreter, you don't use a "print" 
command.  i.e. How can I get the evaluation itself to print instead of 
giving the address of the instance.  Here's a run to demonstrate what I 
mean.

>>> from my import point
>>> p=point(1,2)
>>> print p
(1,2)
>>> p
<my.point instance at 0x00c448b0>
>>> 

I would like ">>> p" to return something like '(1,2)', too.

Also, in the Runtime Services section of the library documentation, I 
see "cpickle" and "operator" listed and I find "test_cpickle.py" and 
"test_operator.py" on my disk, but I don't see the "cpickle.py" or 
"operator.py" anywhere.  Where are they?

/c