Reputation: 161
I've run into this odd behaviour when I use the UUID()
function from the python uuid
module to check one of our test uuids.
from uuid import UUID
uuid1 = UUID('00000000-0000-0000-0000-000000000000', version=1)
print uuid1
00000000-0000-1000-8000-000000000000
without the version it works as expected
uuid0 = UUID('00000000-0000-0000-0000-000000000000')
print uuid0
00000000-0000-0000-0000-000000000000
Is this expected behavour? Are there any other side effects that I need to worry about?
Is there a safer or better way to test uuids in python I should use instead of the UUID()
function or am I misusing this function?
Upvotes: 3
Views: 806
Reputation: 15758
From code comment
The 'version' argument is optional; if given, the resulting UUID will have its variant and version set according to RFC 4122, overriding the given 'hex', 'bytes', 'bytes_le', 'fields', or 'int'.
To generate uuid you can use one of following functions depending on uuid type
uuid1(), uuid3(), uuid4(), uuid5()
And as you already know UUID() to parse UUID into object
Upvotes: 2