__str__ for each function in a class

Xavier Ho contact at xavierho.com
Wed May 19 11:09:24 EDT 2010


On 5/19/2010 1:14 AM, Vincent Davis wrote:

> 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
>>
>
I just wanted to point out that your

self._x = self.new

does not give you a new object. Instead, _x is assigned a reference that
points to this object called 'new', which is passed in during the class
initialisation. I think your variable naming needs some improvement to
show/correct your understanding.

Also, you can just use `x` and `y` for the variable names; you don't need
the underscore. If you want to use a pseudo-private variable, use __x
(double prefix underscore) instead.

Cheers,
Xav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100520/2d043947/attachment-0001.html>


More information about the Python-list mailing list