UUID 检查使用 python UUID 模块更改 UUID

UUID check using python UUID module changes UUID

当我使用 python uuid 模块中的 UUID() 函数来检查我们的一个测试 uuid 时,我 运行 遇到了这种奇怪的行为。

from uuid import UUID uuid1 = UUID('00000000-0000-0000-0000-000000000000', version=1) print uuid1 00000000-0000-1000-8000-000000000000

没有版本它按预期工作 uuid0 = UUID('00000000-0000-0000-0000-000000000000') print uuid0 00000000-0000-0000-0000-000000000000

这是预期的行为吗?我需要担心任何其他副作用吗?

有没有更安全或更好的方法来测试 python 中的 uuid 我应该使用而不是 UUID() 函数还是我滥用了这个函数?

来自代码注释

 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'.

RFC versions

要生成 uuid,您可以根据 uuid 类型使用以下函数之一

uuid1(), uuid3(), uuid4(), uuid5()

你已经知道 UUID() 将 UUID 解析为对象

Python Docs