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

Steven D'Aprano steve at pearwood.info
Thu Dec 6 12:54:24 CET 2012


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.




-- 
Steven


More information about the Tutor mailing list