Printing data members of a class

John Fisher jfisher at are.berkeley.edu
Wed Sep 1 17:39:53 EDT 1999


Hey folks,

I'm trying to set up a class so that when instances of it are printed, a
Python prints just a certain data member of the instance.  For example:

>>> class x:
... 	data = array([1, 2])

>>> y = x()
>>> y
[1 2]

or at least
>>> print y
[1 2]

I've tried playing around with repr, and defining __repr__() in the
class, but haven't had any luck yet.  I'd appreciate any suggestions on
how to do this.

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