[Tutor] Get/Set/Attribute Accessors in Python?

Mark Lawrence breamoreboy at yahoo.co.uk
Thu Dec 6 16:56:31 CET 2012


On 06/12/2012 11:54, Steven D'Aprano wrote:
> On 06/12/12 15:42, Mark Lawrence wrote:
>> On 05/12/2012 16:58, Steven D'Aprano wrote:
>>>
>>> And here is how it should be written in Python:
>>>
>>> class Example(object):
>>> def __init__(self, value):
>>> self.x = value
>>>
>>> instance = Example(42)
>>> print instance.x # gives 42
>>> instance.setx(23)
>>>
>>
>> And introduce error handling while we're at it? Should we consider a
>> CutAndPasteError in Python? :)
>
> Oh the shame! I am disgraced!
>
> /me hangs head in shame
>
> Thanks for catching the error.
>

I can't say I'll lose too much sleep over it. IIRC 30 years ago an 
emergency release was done, all signed off by the appropriate people, 
and the integration team couldn't load the software onto the system. 
Why?  It handn't compiled, someone had taken out one line too many with 
the editor!!!  Now we're giving advice in relatively real time, and 
sometimes we get it wrong.  Thankfully not so costly to the UK taxpayer.

-- 
Cheers.

Mark Lawrence.



More information about the Tutor mailing list