uuid in python
2016-06-14 19:33
429 查看
>>> import uuid # 生成基于计算机主机ID和当前时间的UUID >>> uuid.uuid1() 输出结果: UUID('a8098c1a-f86e-11da-bd1a-00112444be1e') # 基于命名空间和一个字符的MD5加密的UUID >>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org') 输出结果: UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e') # 随机生成一个UUID >>> uuid.uuid4() 输出结果: UUID('16fd2706-8baf-433b-82eb-8c7fada847da') # 基于命名空间和一个字符的SHA-1加密的UUID >>> 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) #根据十六进制字符生成UUID(英语好的请看上面的原话) >>> x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}') # convert a UUID to a string of hex digits in standard formUUID #转换成十六进制的UUID表现字符(英语好的请看上面的原话) >>> str(x) 输出结果: '00010203-0405-0607-0809-0a0b0c0d0e0f' # 获取原始UUID的16位字符 >>> x.bytes 输出结果: '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f' #生成16位字符的UUID >>> uuid.UUID(bytes=x.bytes) 输出结果: UUID('00010203-0405-0607-0809-0a0b0c0d0e0f')
相关文章推荐
- Python基础(一)(基于Python2.7)
- python 学习1
- Eclipse Download and Installation (for Python) Instructions
- Python简介与入门(基于Python2.7)
- python非字符串与字符产链连接
- Python里有趣的列表解析和生成器表达式
- Python中的super使用
- python基础之坑爹正则表达式
- Python下json.loads()中文字符出错解决
- 使用python脚本备份crontab定时任务
- python位操作学习笔记
- Python入门简单的静态网页爬虫1.0 (爬虫架构 )
- python脚本之过滤关键字
- 笔记 python与json数据
- Python3 字符编码
- python多线程调用exit无法退出
- Python的Asyncore异步Socket模块及实现端口转发的例子
- python中的正则表达式
- python一个简单的登录
- Python实现TCP/IP协议下的端口转发及重定向示例