[Tutor] __getattr__ causes TypeError

Jan Eden lists at janeden.org
Sun Sep 25 19:47:38 CEST 2005


Hi,

I experienced a strange side effect using a custom __getattr__ method.

For a certain attribute, I'd like to return the value of another attribute if the former is not present. So I wrote:

def __getattr__(self, attrname):
    if attrname == 'own_type': return self.child_type
    else: AttributeError, attrname

But if I include this in my base class, I get a TypeError somewhere else:

  File "/Users/jan/Sites/janeden/cgi-bin/Pythonsite/Show.py", line 24, in Populate
   self.page_head = re.sub('%%author%%', self.first_name+' '+self.last_name, self.page_head)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

How can this possibly be related? I am clueless.

Best,

Jan
-- 
If all else fails read the instructions. - Donald Knuth


More information about the Tutor mailing list