[Zope] Seing if an attribute exist in an ObjectManager

Jerome Alet alet@unice.fr
Tue, 29 May 2001 14:35:56 +0200 (MET DST)


On Tue, 29 May 2001, [iso-8859-1] Max M=F8ller Rasmussen wrote:

> I have set an image in an ObjectManager object like this:
>=20
>     imID =3D 'laeringsGraf'   =20
>     self._setObject(imID, OFS.Image.Image(imID,'L=E6rings graf',''))
>     self._getOb(imID).update_data(data)
>=20
> I only want to draw it if it isn't there allready
>=20
> How do I then check if it allready exists?
> I guess it's something like::
>=20
>     if not hasattr(self, imID): ??
>     or
>     if not self._has_attr(imID)

with hasattr you'll check if the object exists but taking care of the
acquisition.

what you need is:

=09if imID not in self.objectIds() :
=09=09# doesn't exist
=09else:
=09=09# already exists

hoping this helps.

bye,

Jerome Alet