[Zope] Which method to generate IDs for objects?
Tim Hicks
timNOT_THIS@sitefusion.co.uk
Wed, 16 Jan 2002 12:21:45 -0000
> I am just experimenting with ZClasses and I ran into the following
problem:
> when I instantiate an object this object needs an unique ID. There are
some
> ways to generate this. First of all I thought of the system time as ID,
but
> this can make problems, even though not with high probability. Does
anybody
> out there have a better solution, I think of an ID generation like in a
> sequence: object_id_001, object_id_002, ... but how can I determine the
> last object ID?
>
> Other (better, more simple) ideas?
I don't know if this is very efficient/elegant/etc*, but I use it to get a
unique id within a folder...
-------------
intid = 1
while 1:
if hasattr(photo_folder, str(intid)):
intid = intid + 1
else:
photo_folder.manage_addProduct['ExtFile'].manage_addExtImage(id=str(intid),
file=f_request[photo], create_prev=1, maxx=50, maxy=50, ratio=1)
break
-------------
photo_folder is a previously defined in the script object.
hth
tim
* I guess it gets a bit less useful as you start having lots of objects in
your folder... I have a max of 4.