[Zope] Which method to generate IDs for objects?

Max M maxm@mxm.dk
Thu, 17 Jan 2002 14:32:07 +0100


Maik Jablonski wrote:

> hello juergen,
> 
> i think this will give you really unique id's...  part of a python script
> 
> # get a unique id in context for an object
> 
> id = len(context.objectIds())    # get the number of objects in context 
> => maybe already a free id?
> while hasattr(context,str(id)):  # to be sure: test if id exists already 
> and search for a free id...
>     id = id + 1
> return(str(id))                     # and that's what we need...


In reality it is not guaranteed to give a unique id. Another proces 
could come to the same id if you are unlucky.

you should probably use the FScounter to be certain.

regards Max M