python学习之-- 生成唯一ID

Posted 十年如一..bj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python学习之-- 生成唯一ID相关的知识,希望对你有一定的参考价值。

以下以2种方法生成唯一ID

def uuid_method():
    """第一种方法"""
    import uuid
    return str(uuid.uuid1())

print(uuid_method())

  

def time_method():
    """第二种方法"""
    import time, hashlib
    m = hashlib.md5()
    m.update(bytes(str(time.time()), encoding=‘utf-8‘))
    return m.hexdigest()

print(time_method())

  

以上是关于python学习之-- 生成唯一ID的主要内容,如果未能解决你的问题,请参考以下文章

Python学习之对象基础

Python学习之三大名器-装饰器迭代器生成器

Python面向对象学习之八,装饰器

python学习之网络编程

python学习之字典

python学习之生成器yield