[Python-Dev] UUID module (original) (raw)

Thomas Heller theller at python.net
Sat Jun 10 21:30:52 CEST 2006


Phillip J. Eby wrote:

At 06:39 PM 6/10/2006 +0200, Thomas Heller wrote:

I don't know if this is the uuidgen you're talking about, but on linux there is libuuid:

>>> from ctypes import * >>> lib = CDLL("libuuid.so.1") >>> uuid = createstringbuffer(16) >>> lib.uuidgenerate(byref(uuid)) 2131088494 >>> from binascii import hexlify >>> hexlify(buffer(uuid)) '0c77b6d7e5f940b18e29a749057f6ed4' >>> Nice. :) But no, this one's a uuidgen() system call on FreeBSD>=5.0 and NetBSD>=2.0; it may be in other BSD variants as well... perhaps OS X?

For completeness :-), although its probably getting off-topic:

$ uname -a FreeBSD freebsd 6.0-RELEASE FreeBSD 6.0-RELEASE #0: Thu Nov 3 09:36:13 UTC 2005 root at x64.samsco.home:/usr/obj/usr/src/sys/GENERIC i386 $ python Python 2.4.1 (#2, Oct 12 2005, 01:36:32) [GCC 3.4.4 [FreeBSD] 20050518] on freebsd6 Type "help", "copyright", "credits" or "license" for more information.

from ctypes.util import findlibrary findlibrary("c") 'libc.so.6' from ctypes import * libc = CDLL("libc.so.6") uuid = createstringbuffer(16) libc.uuidgen(uuid, 1) 0 uuid[:] '\xd2\xff\x8e\xe3\xa3\xf8\xda\x11\xb0\x04\x00\x0c)\xd1\x18\x06' $

On OS X, this call is not available, but /usr/lib/libc.dylib has a uuid_generate function which is apparently compatible to the linux example I posted above.

Thomas



More information about the Python-Dev mailing list