python uuid模块使用实例

WBOY
Release: 2016-06-10 15:15:46
Original
1332 people have browsed it

uuid是一种唯一标识,在许多领域作为标识用途。python的uuid模块就是用来生成它的。
闲话不说,python提供的生成uuid的方法一共有4种,分别是:

1.从硬件地址和时间生成
2.从md5算法生成
3.随机生成
4.从SHA-1算法生成

他们在uuid模块里对应uuid1, uuid3, uuid4, uuid5这几个方法,注意没有uuid2。
下面是示例:

复制代码 代码如下:

#-*- encoding: gb2312 -*-
import uuid

print uuid.uuid1()
print uuid.uuid3(uuid.NAMESPACE_DNS, 'testme')
print uuid.uuid4()
print uuid.uuid5(uuid.NAMESPACE_DNS, 'testme')

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!