Generating a unique identifier
Ben Finney
bignose+hates-spam at benfinney.id.au
Fri Sep 7 19:47:42 EDT 2007
Will Maier <willmaier at ml1.net> writes:
> On Fri, Sep 07, 2007 at 12:03:23PM -0000, Steven D'Aprano wrote:
> [...]
> > which is easy enough, but I thought I'd check if there was an
> > existing solution in the standard library that I missed. Also, for
> > other applications, I might want them to be rather less
> > predictable.
>
> 2.5 includes the uuid module for RFC 4122 universally-unique IDs:
>
> http://docs.python.org/lib/module-uuid.html
I second this recommendation. If you want arbitrary unique IDs that
are not a function of the data they identify, the simplest solution is
a monotonically-increasing serial number. If you want more than that,
you might as well go straight to the standard UUIDs.
Even if you're not using Python 2.5, grab the external 'python-uuid'
package for your operating system and use that. If you use the options
for including random elements, the generated UUIDs will even satisfy
your "unpredictable" requirement.
--
\ "This sentence contradicts itself -- no actually it doesn't." |
`\ -- Douglas Hofstadter |
_o__) |
Ben Finney
More information about the Python-list
mailing list