推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
miniyao
V2EX  ›  Python

uuid 默认的 NAMESPACE_DNS 是根据什么 DNS 生成的?

  •  
  •   miniyao · Apr 14, 2018 · 4437 views
    This topic created in 3042 days ago, the information mentioned may be changed or developed.

    用 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 生成的?须要改成自定义的吗?

    3 replies    2018-04-14 23:13:44 +08:00
    eastpiger
        1
    eastpiger  
       Apr 14, 2018 via Android   ❤️ 1
    他不是根据 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.
    miniyao
        2
    miniyao  
    OP
       Apr 14, 2018
    @eastpiger 谢谢!看了官方文档中: 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 都可以吗?)
    julyclyde
        3
    julyclyde  
       Apr 14, 2018
    @miniyao 你看 Java 的类名也是个域名(逆序写出来的)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5700 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 03:25 · PVG 11:25 · LAX 20:25 · JFK 23:25
    ♥ Do have faith in what you're doing.