UUID objects (universally unique identifiers) according to RFC 4122.
This module provides immutable UUID objects (class UUID) and the functions
uuid1(), uuid3(), uuid4(), uuid5() for generating version 1, 3, 4, and 5
UUIDs as specified in RFC 4122.
If all you want is a unique ID, you should probably call uuid1() or uuid4().
Note that uuid1() may compromise privacy since it creates a UUID containing
the computer's network address. uuid4() creates a random UUID.
Typical usage:
>>> import uuid
# make a UUID based on the host ID and current time
>>> uuid.uuid1()
UUID('a8098c1a-f86e-11da-bd1a-00112444be1e')
# make a UUID using an MD5 hash of a namespace UUID and a name
>>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org')
UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e')
# make a random UUID
>>> uuid.uuid4()
UUID('16fd2706-8baf-433b-82eb-8c7fada847da')
# make a UUID using a SHA-1 hash of a namespace UUID and a name
>>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')
UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d')
# make a UUID from a string of hex digits (braces and hyphens ignored)
>>> x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}')
# convert a UUID to a string of hex digits in standard form
>>> str(x)
'00010203-0405-0607-0809-0a0b0c0d0e0f'
# get the raw 16 bytes of the UUID
>>> x.bytes
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t \x0b\x0c \x0e\x0f'
# make a UUID from a 16-byte string
>>> uuid.UUID(bytes=x.bytes)
UUID('00010203-0405-0607-0809-0a0b0c0d0e0f')
This module works with Python 2.3 or higher.
[/size][size=x-small][/size][size=medium]
分享到:
相关推荐
他们在uuid模块里对应uuid1, uuid3, uuid4, uuid5这几个方法,注意没有uuid2。 下面是示例: 复制代码 代码如下: #-*- encoding: gb2312 -*- import uuid print uuid.uuid1() print uuid.uuid3(uuid.NAMESPACE_DNS,...
UUID UUID 是 通用唯一识别码(Universally Unique Identifier)的缩写 目的,是让分布式系统中的所有元素,都能有唯一的辨识信息 不需要通过中央控制端来做辨识信息的指定 场景: 不需考虑数据库创建时的...
主要介绍了Python内置模块hashlib、hmac与uuid用法,结合实例形式较为详细的分析了hashlib、hmac与uuid模块的概念、功能及简单使用方法,需要的朋友可以参考下
python的uuid都是32位的,比较长,处理起来效率比较低。这篇文章主要介绍了Python生成短uuid的方法,需要的朋友可以参考下
UUID(Universally Unique Identifier)是通用唯一识别码,在许多领域用作标识,比如我们常用的数据库也可以用它来作为主键,原理...python有一个模块叫做uuid,导入它就可以使用它的四个方法了。注意这四个方法依次是
主要介绍了Python使用uuid模块生成唯一标识ID,需要的朋友可以参考下
主要介绍了Python通用唯一标识符uuid模块使用案例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
资源来自pypi官网。 资源全名:micropython-uuid-0.1.tar.gz
使用第三方模块Underscore.js,Immutable.js,UUID(源代码+截图)使用第三方模块Underscore.js,Immutable.js,UUID(源代码+截图)使用第三方模块Underscore.js,Immutable.js,UUID(源代码+截图)使用第三方模块...
HC5661A开启root权限过程中获取不到uuid的,请刷该固件即可成功开启。
主要介绍了java获取UUID与UUID的校验,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
利用UUID生成完全不重复的数字 package com.example.uuid; import java.util.UUID; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View....
return "".join(str(uuid.uuid4()).split("-")).upper() 补充拓展:随机产生32位随机数 1.通过uuid UUID.randomUUID().toString()这个方法可以得到32位数字和四个“-”穿插在其中 再调用 .replace(“-“,””)得到...
PB生成UUID