[Zope] overwrite __getattr__
Dragos Chirila
d.chirila@bucarest.finsiel.ro
Sat, 5 Apr 2003 15:49:30 +0300
This is a multi-part message in MIME format.
------=_NextPart_000_03F6_01C2FB8A.F2295990
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi
I have a class that extends 'Folder' and in this class i have a property =
of type dictionary.
This dictionary has the following meaning: key =3D property id, value =
=3D a value (string or whatever).
I want to use the catalog to index and search for this kind of objects.
For each property I have an index in catalog.
Let's say the dictionary is {'field1' : 'value of field 1', 'field2': =
'value of field2'}.
I also have 2 indexes named 'field1' and 'field2'.
The problem is that when the catalog tries to catalog my object doesn't =
find the properties 'field1' and 'field2' for my object !!!
So, I overwrite __getattr__ to tell it how to handle these properties
def __getattr__(self, name):
if name=3D=3D'field1':
return self.dict['field1']
elif name=3D=3D'field2':
return self.dict['field2']
else:
-- How do I tell him to execute the default ?????
=20
I want to handle __getattr__ just for some special attributtes names
10x
Dragos
------=_NextPart_000_03F6_01C2FB8A.F2295990
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I have a class that extends 'Folder' =
and in this=20
class i have a property of type dictionary.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>This dictionary has the following =
meaning: key =3D=20
property id, value =3D a value (string or whatever).</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I want to use the catalog to index and =
search for=20
this kind of objects.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>For each property I have an index in=20
catalog.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Let's say the dictionary is {'field1' : =
'value of=20
field 1', 'field2': 'value of field2'}.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I also have 2 indexes named 'field1' =
and=20
'field2'.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>The problem is that when the catalog =
tries to=20
catalog my object doesn't find the properties 'field1' and 'field2' for =
my=20
object !!!</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>So, I overwrite __getattr__ to tell it =
how to=20
handle these properties</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>def __getattr__(self, =
name):</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> if =
name=3D=3D'field1':</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
return=20
self.dict['field1']</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> elif =
name=3D=3D'field2':</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
return=20
self.dict['field2']</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> else:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
-- How do I=20
tell him to execute the default ?????</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I want to handle __getattr__ just for =
some special=20
attributtes names</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>10x</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Dragos</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV></BODY></HTML>
------=_NextPart_000_03F6_01C2FB8A.F2295990--