如何在Python中根据当前日期和时间生成固定长度的哈希? [英] How to generate a fixed-length hash based on current date and time in Python?

查看:83
本文介绍了如何在Python中根据当前日期和时间生成固定长度的哈希?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想基于当前日期和时间生成固定长度(例如10个字符)的哈希.时间.此哈希将附加到我的用户上传的文件的名称上.如何在Python中做到这一点?

I want to generate a fixed-length (say 10 characters) hash based on current date & time. This hash will be append to names of the uploaded files from my users. How can I do that in Python?

推荐答案

包括的电池:

import hashlib
import time

hash = hashlib.sha1()
hash.update(str(time.time()))
print hash.hexdigest()
print hash.hexdigest()[:10]

这篇关于如何在Python中根据当前日期和时间生成固定长度的哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆