Re: [Zope] Unique ID generation
On Thu, 25 Jan 2001, Timothy Wilson wrote: > Try adding the following to your ZClass add method: > > > > > This will use the ZopeTime() as the id of your instance. I doubt you can add > them faster enough to get the same one twice. :-) When you add instances programatically, than you can add 2 in 1 second without doubt. I use this python code: def genId(client, namespace, prefix=''): no=int(client.ZopeTime()) while namespace.hasattr(client, prefix+str(no)): no=no+1 return prefix+str(no) [EMAIL PROTECTED], [EMAIL PROTECTED] /--\ | `long long long' is too long for GCC | \--/ ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Unique ID generation
On 25 Jan 2001, Tim Moore wrote: > I'm writing a simple ZClass (and a second ZClass which contains the > first) and I would like the constructor for this class to be able to > auto-generate unique IDs for the instances rather than making the > owner choose one. Some people call me "Tim" too. :-) Try adding the following to your ZClass add method: This will use the ZopeTime() as the id of your instance. I doubt you can add them faster enough to get the same one twice. :-) -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/ W. St. Paul, MN | | http://slashdot.org/ [EMAIL PROTECTED] || http://linux.com/ ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Unique ID generation
Using time is very common eg _.str(_.int(ZopeTime)), or I did a HowTo on using FSCounter to do this: http://www.zope.org/Members/andym/FSCounter/unique_ids -- Andy McKay. - Original Message - From: "Tim Moore" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, January 25, 2001 2:55 PM Subject: [Zope] Unique ID generation > I'm writing a simple ZClass (and a second ZClass which contains the > first) and I would like the constructor for this class to be able to > auto-generate unique IDs for the instances rather than making the > owner choose one. What I've tried isn't working, but I don't really > know what I'm doing here...I figure this must be a fairly common > problem, so what is the best way to handle it? The ID needs only be > unique within its container object (i.e., doesn't have to be globally > unique). I have full control over the container class, so solutions > involving setting properties on that class are OK. > > TIA, > -- > Tim Moore > > ___ > Zope maillist - [EMAIL PROTECTED] > http://lists.zope.org/mailman/listinfo/zope > ** No cross posts or HTML encoding! ** > (Related lists - > http://lists.zope.org/mailman/listinfo/zope-announce > http://lists.zope.org/mailman/listinfo/zope-dev ) > ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] Unique ID generation
I'm writing a simple ZClass (and a second ZClass which contains the first) and I would like the constructor for this class to be able to auto-generate unique IDs for the instances rather than making the owner choose one. What I've tried isn't working, but I don't really know what I'm doing here...I figure this must be a fairly common problem, so what is the best way to handle it? The ID needs only be unique within its container object (i.e., doesn't have to be globally unique). I have full control over the container class, so solutions involving setting properties on that class are OK. TIA, -- Tim Moore ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )