[Texas] Trouble with one of the Koans
Mark Sharp
msharp at sfbr.org
Fri Sep 3 16:57:24 CEST 2010
In the about_attribute_access.py of the Python 3.1 koans, the following class is defined. Although I can get the tests to pass, I am missing the point.
Do you know of any discussion of the koans? I have not located one. Alternatively can you direct me to someone that would be willing to explain what this class is teaching?
Mark
class PossessiveSetter(object):
def __setattr__(self, attr_name, value):
new_attr_name = attr_name
if attr_name[-5:] == 'comic':
new_attr_name = "my_" + new_attr_name
elif attr_name[-3:] == 'pie':
new_attr_name = "a_" + new_attr_name
object.__setattr__(self, new_attr_name, value)
def test_setattr_intercepts_attribute_assignments(self):
fanboy = self.PossessiveSetter()
fanboy.comic = 'The Laminator, issue #1'
fanboy.pie = 'blueberry'
self.assertEqual(__, fanboy.a_pie)
prefix = '__'
self.assertEqual("The Laminator, issue #1", getattr(fanboy, prefix + '_comic'))
R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Southwest Foundation for
Biomedical Research
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msharp at sfbr.org<mailto:msharp at sfbr.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/texas/attachments/20100903/268471e0/attachment.html>
More information about the Texas
mailing list