Printing data members of a class
John Fisher
jfisher at are.berkeley.edu
Fri Sep 3 15:41:29 EDT 1999
In article <37cda459.14483153 at news.erols.com>,
kernr at mail.ncifcrf.gov (Robert Kern) wrote:
> class x:
> data = array([1, 2])
>
> def __str__(self):
> return str(self.data)
>
> __repr__ = __str__
> # If you must; it would be better to have __repr__ return a string
> # that could be meaningfully eval'ed, but if you need the
> # behaviour in your first example, this is how to do it.
I don't anticipate any need for __repr__ in this class except for
printing. Your solution is perfect. Thanks.
John
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
More information about the Python-list
mailing list