[ZODB-Dev] "Advanced ZODB for Python Programmers" article: volatile example
Wichert Akkerman
wichert at wiggy.net
Mon May 24 08:02:40 EDT 2010
On 5/24/10 13:59 , Vincent Pelletier wrote:
> Hi.
>
> I think the example on volatile attributes given in "Advanced ZODB for Python
> Programmers" article[1] shows a bad practice.
>
>> From the article:
> if hasattr(self, '_v_image'):
> return self._v_image
>
> This should be rewritten as:
> try:
> return self._v_image
> except AttributeError:
or better:
marker = []
value = getattr(self, "_v_image", marker)
if value is not marker:
return value
which prevents the exception overhead.
Wichert.
More information about the ZODB-Dev
mailing list