V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2018-04-14 10:35:47 +08:00 · 3830 次点击
    这是一个创建于 2176 天前的主题,其中的信息可能已经有所发展或是发生改变。

    用 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 条回复    2018-04-14 23:13:44 +08:00
    eastpiger
        1
    eastpiger  
       2018-04-14 11:36:57 +08:00 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
       2018-04-14 11:57:45 +08:00
    @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  
       2018-04-14 23:13:44 +08:00
    @miniyao 你看 Java 的类名也是个域名(逆序写出来的)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2788 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 14:45 · PVG 22:45 · LAX 07:45 · JFK 10:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.