Python中uuid默认的NAMESPACE_DNS是根据什么DNS生成的?
用 uuid3()生成 uuid:
uuid.uuid3(uuid.NAMESPACE_DNS, 'string_a')
官方文档就一句:
The following standard UUIDs are for use with uuid3() or uuid5().
NAMESPACE_DNS = UUID('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
这个 '6ba7b810-9dad-11d1-80b4-00c04fd430c8' 是根据什么 DNS 生成的?须要改成自定义的吗?
Python中uuid默认的NAMESPACE_DNS是根据什么DNS生成的?
他不是根据 DNS 生成的,他是一个预置的 namesapce 标记,一般这个 namespace 内的值是 dns 类型的数据。
Namespace 可以是任意 uuid 字符串,你可以选择 uuid1 或者 uuid4 或者自己随便编造一个合法数据使用。
根据文档,可以找到预置的 uuid dns namespace 是怎么算的。For version 3 and version 5 UUIDs the additional command line arguments namespace and name have to be given. The namespace is either a UUID in string representation or an identifier for internally pre-defined namespace UUIDs (currently known are “ns:DNS”, “ns:URL”, “ns:OID”, and “ns:X500”). The name is a string of arbitrary length.
谢谢!看了官方文档中: https 冒号 //docs 点 python 点 org/3/library/uuid.html
有这么一句说明:
uuid.NAMESPACE_DNS
When this namespace is specified, the name string is a fully-qualified domain name.
你说的 The name is a string of arbitrary length. 文档中说明的那句:如果指定了 namesapce,the name string is a fully-qualified domain name. (为什么还要 fully-qualified domain name ?不是 arbitrary length 的 string 都可以吗?)
你看 Java 的类名也是个域名(逆序写出来的)


