documentation on the uuid
module说:
UUID.
variant
¶The UUID variant, which determines the internal layout of the UUID. This will be one of the integer constants RESERVED_NCS, RFC_4122, RESERVED_MICROSOFT, or RESERVED_FUTURE.
然后:
uuid.
RESERVED_NCS
¶Reserved for NCS compatibility.
uuid.
RFC_4122
¶Specifies the UUID layout given in RFC 4122.
uuid.
RESERVED_MICROSOFT
¶Reserved for Microsoft compatibility.
uuid.
RESERVED_FUTURE
¶Reserved for future definition.
鉴于此,我希望在访问这些属性时看到整数。然而:
>>> import uuid
>>> u = uuid.uuid4()
>>> u.variant
'specified in RFC 4122'
>>> uuid.RESERVED_NCS
'reserved for NCS compatibility'
>>> uuid.RFC_4122
'specified in RFC 4122'
>>> uuid.RESERVED_MICROSOFT
'reserved for Microsoft compatibility'
>>> uuid.RESERVED_FUTURE
'reserved for future definition'
这在 2.7.9 和 3.4.2 中产生了相同的结果,而且我还没有找到任何版本的文档表明这些常量可能是字符串。我可以在这个问题上产生的最相关的搜索结果恰好是这个模块的源代码(在 SVN 或 GitHub 上),其中包含以下语句:
RESERVED_NCS, RFC_4122, RESERVED_MICROSOFT, RESERVED_FUTURE = [
'reserved for NCS compatibility', 'specified in RFC 4122',
'reserved for Microsoft compatibility', 'reserved for future definition']
鉴于我在解释器中看到的结果,这是完全有道理的,但我不能对文档说同样的话。这是一个简单的文档错误,还是在某个地方这些属性确实是整数,正如文档所 promise 的那样?这里发生了什么?
最佳答案
这是文档中的一个错误。我在 official bug tracker 中提交了它。 ,并且已通过删除“整数”一词来修复它:
I simply remove the type description since I think the type of the constants doesn't matter here.
关于python - UUID 变体何时会是整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39908518/