python str字符串转uuid实例


Posted in Python onMarch 03, 2020

uuid str int 之间的转换

import uudi
 
#str 转 uuid
uuid.UUID('12345678123456781234567812345678')
uuid.UUID(hex='12345678123456781234567812345678')
uuid.UUID('{12345678-1234-5678-1234-567812345678}')
uuid.UUID('urn:uuid:12345678-1234-5678-1234-567812345678')
#Out:UUID('12345678-1234-5678-1234-567812345678')
 
uuid.UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678))
#Out:UUID('12345678-1234-5678-1234-567812345678')
 
#int 转 uuid
uuid.UUID(int=0x12345678123456781234567812345678)
#Out:UUID('12345678-1234-5678-1234-567812345678')
 
#uuid 转 str
str(uuid.uuid4())
#Out:'a0565f88-b20a-4cc1-a6de-11f046bb7100'
type(str(uuid.uuid4()))
#Out:str
python的uuid模块提供UUID类和函数uuid1(), uuid3(), uuid4(), uuid5() 来生成1, 3, 4, 5各个版本的UUID

uuid.uuid1([node[, clock_seq]]) : 主机ID, 序列号, 和时间戳来生成UUID, 可保证全球范围的唯一性
uuid.uuid3(namespace, name) : 基于命名空间和名字的MD5散列值
uuid.uuid4() : 基于随机数
uuid.uuid5(namespace, name) : 基于命名空间和名字的SHA-1散列值,同uuid3

补充拓展:python字符串和time互转与时间的加减另加uuid

咱们看代码吧!

# -*-coding:utf-8 -*-
__author__ = "ZJL"
 
import uuid,time,datetime
 
#uuid4产生32位随机字母加数字
print(str(uuid.uuid4()).replace("-",""))
#uuid3产生基于名字的MD5散列值
print(str(uuid.uuid3(uuid.NAMESPACE_DNS,"username")).replace("-",""))
 
#time转字符串
time_num = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
print(time_num)
 
#字符串转time
t = time.strptime(time_num, '%Y-%m-%d %H:%M:%S')
y,m,d,H,M,S = t[:6]
print(t)
print(datetime.datetime(y,m,d,H,M,S))
 
#时间的加减
now_time = datetime.datetime.now()
#当前时间加半小时
yes_time = now_time + datetime.timedelta(hours=+0.5)
#比较时间大小
if now_time>yes_time:
  print("ok")
else:
  print("no")
#当前时间减一天
# yes_time = now_time + datetime.timedelta(days=-1)
yes_time_nyr = yes_time.strftime('%Y-%m-%d %H:%M:%S')
print(yes_time_nyr)

结果:

python str字符串转uuid实例

import time, datetime
#一个月前
today1 = datetime.datetime.today()
astmonth = datetime.datetime(today1.year, (today1.month - 1), today1.day, today1.hour, today1.minute,today1.second)

以上这篇python str字符串转uuid实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
跟老齐学Python之for循环语句
Oct 02 Python
Python中用startswith()函数判断字符串开头的教程
Apr 07 Python
python魔法方法-自定义序列详解
Jul 21 Python
python getopt详解及简单实例
Dec 30 Python
python中map()函数的使用方法示例
Sep 29 Python
python爬虫之xpath的基本使用详解
Apr 18 Python
python GUI库图形界面开发之PyQt5开发环境配置与基础使用
Feb 25 Python
pytorch判断是否cuda 判断变量类型方式
Jun 23 Python
浅析Python __name__ 是什么
Jul 07 Python
python通过函数名调用函数的几种场景
Sep 23 Python
Python爬取豆瓣数据实现过程解析
Oct 27 Python
python munch库的使用解析
May 25 Python
PyCharm取消波浪线、下划线和中划线的实现
Mar 03 #Python
python生成并处理uuid的实现方式
Mar 03 #Python
python实现在线翻译功能
Mar 03 #Python
Python configparser模块配置文件过程解析
Mar 03 #Python
Python生成六万个随机,唯一的8位数字和数字组成的随机字符串实例
Mar 03 #Python
Django CSRF认证的几种解决方案
Mar 03 #Python
python实现电子词典
Mar 03 #Python
You might like
探讨PHP使用eAccelerator的API开发详解
2013/06/09 PHP
如何使用php等比例缩放图片
2016/10/12 PHP
Mootools 1.2教程 事件处理
2009/09/15 Javascript
js利用prototype调用Array的slice方法示例
2014/06/09 Javascript
js实现Form栏显示全格式时间时钟效果代码
2015/08/19 Javascript
JavaScript:Date类型全面解析
2016/05/19 Javascript
JS实现新建文件夹功能
2017/06/17 Javascript
js 概率计算(简单版)
2017/09/12 Javascript
浏览器调试动态js脚本的方法(图解)
2018/01/19 Javascript
使用vue-cli创建项目的图文教程(新手入门篇)
2018/05/02 Javascript
JavaScript 正则命名分组【推荐】
2018/06/07 Javascript
json数据传到前台并解析展示成列表的方法
2018/08/06 Javascript
angularjs 动态从后台获取下拉框的值方法
2018/08/13 Javascript
nodejs制作小爬虫功能示例
2020/02/24 NodeJs
[01:09:40]Newbee vs Pain 2018国际邀请赛小组赛BO2 第一场 8.16
2018/08/17 DOTA
Python时区设置方法与pytz查询时区教程
2013/11/27 Python
使用Python的Flask框架构建大型Web应用程序的结构示例
2016/06/04 Python
浅谈Python 对象内存占用
2016/07/15 Python
Python断言assert的用法代码解析
2018/02/03 Python
Python 给某个文件名添加时间戳的方法
2018/10/16 Python
详解python函数的闭包问题(内部函数与外部函数详述)
2019/05/17 Python
给 TensorFlow 变量进行赋值的方式
2020/02/10 Python
阿里健康大药房:阿里自营网上药店
2017/08/01 全球购物
Onzie官网:美国时尚瑜伽品牌
2019/08/21 全球购物
新加坡第一大健康与美容零售商:屈臣氏新加坡(Watsons Singapore)
2020/12/11 全球购物
计算机求职信
2013/12/01 职场文书
电子银行营销方案
2014/02/22 职场文书
颁奖晚会主持词
2014/03/25 职场文书
航海技术专业毕业生求职信
2014/04/06 职场文书
信访维稳工作汇报
2014/10/27 职场文书
2015年党员创先争优承诺书
2015/01/22 职场文书
行政介绍信范文
2015/05/04 职场文书
2015年小学数学教师工作总结
2015/05/20 职场文书
让世界充满爱观后感
2015/06/10 职场文书
信息技术教研组工作总结
2015/08/13 职场文书
Django数据库(SQlite)基本入门使用教程
2022/07/07 Python