[Tutor] __getattr__ causes TypeError
lists at janeden.org
Sun Sep 25 19:51:18 CEST 2005
Sorry! Found the typo.
Jan Eden wrote on 25.09.2005:
>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
> self.page_head = re.sub('%%author%%', self.first_name+' '+self.last_name,
>TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
>How can this possibly be related? I am clueless.
Any sufficiently advanced technology is indistinguishable from a Perl script. - Programming Perl
More information about the Tutor