__str__ for each function in a class
Vincent Davis
vincent at vincentdavis.net
Wed May 19 01:14:49 EDT 2010
I am sure this is easy but I am not sure how to do it and google was failing
me.
Lets say I have a class() with an def x() and def y() and I want
print(class.x) and (class.y) to have custom prints (__str__) how do I do
this
For example
class C(object):
def __init__(self, new):
self.letter = dict(a=1,b=2,c=3, amin=np.amin)
self.new = new
self._x = None
self._Y = None
@property
def x(self):
"""I'm the 'x' property."""
self._x = self.new
return self._x
@property
def y(self):
"""I'm the 'x' property."""
self._y = self.new*-1
return self._y
.......
>>> print(class.x)
****x****
>>> print(class.y)
---------
++++y++++
---------
*Vincent Davis
720-301-3003 *
vincent at vincentdavis.net
my blog <http://vincentdavis.net> |
LinkedIn<http://www.linkedin.com/in/vincentdavis>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100518/198c2fe3/attachment.html>
More information about the Python-list
mailing list