一、时间模块

时间的几种形式:时间戳,结构化时间,字符串时间
import time
print(time.time()) # 仅仅是当前时间的时间戳 float
print(time.localtime()) # 时间对象
s = time.localtime() # 结构化时间对象
s2 = time.gmtime() # 结构化时间对象 UTC时间
print(s)
print(s2) res0 = time.mktime(time.localtime()) # 将结构化时间 转化成 时间戳 res1 = time.localtime(1412414234) # 将时间戳 转化成 结构化时间 res2 = time.strftime("%Y-%m-%d", time.localtime()) # 将结构化时间 转化成 字符串时间 res3 = time.strptime("1900:03:12", "%Y-%m-%d") # 将字符串时间 转化成 结构化时间 res4 = time.asctime() # 将结构化时间 转化成 固定合适字符串时间 'Sun Nov 25 10:03:43 1979' res5 = time.ctime() # 将时间戳 转化成 固定格式字符串时间 'Sun Nov 25 10:03:43 1979' res6 = time.sleep() # 睡几秒,暂停几秒

  

二、随机数模块

import random

print(random.random())      # (0, 1) float类型

print(random.uniform(1, 3))     # float类型

print(random.randint(1, 3)) # [1, 3]  int

print(random.randrange(1, 3))   #[1, 3) int

print(random.choice([1, 2, 'hello']))  # 随机

print(random.sample((1, 5), 2))    # 列表元素任意两个组合

l = [111, 222, 333, 444]
# random.shuffle(l)
print(random.shuffle(l))
# 练习:五位数字大小写字母验证码
def valdate_code():
ret = ""
for i in range(5):
num = random.randint(0, 9)
alfa = chr(random.randint(97, 122))
alfa2 = chr(random.randint(65, 90))
s = random.choice([str(num), alfa, alfa2])
ret = ret + s
return ret
print(valdate_code())
三、摘要算法hashlib

摘要算法应用1:文件一致性校验
# md5计算
import hashlib md5_obj=hashlib.md5()
md5_obj.update(b"helloworld") print(md5_obj.hexdigest()) # fc5e038d38a57032085441e7fe7010b0
# 如果数据量大,可以分块调用update,下面的计算值跟直接计算‘yuanhelloworld’值一样
import hashlib md5_obj=hashlib.md5() md5_obj.update(b"yuan")
md5_obj.update(b"helloworld") print(md5_obj.hexdigest()) #423bf62926c0e5bfba81a94977fdb224
摘要算法应用2:登录
username                pwd

admin                 admin
4523453452345 4732467812364342423
4523453452345 31423149238147982 admin ----------- 4732467812364 adminjindongdf ----------- 4732467812364342423 root ----------- 892345789432 12345678 ----------- 6732456784325 加盐处理 salt
md5_obj=hashlib.md5("salt")
md5_obj.update("admin") # saltadmin

  

python3 time、random、hashlib模块的更多相关文章

  1. python接口自动化测试二十七:密码MD5加密 ''' MD5加密 ''' # 由于MD5模块在python3中被移除 # 在python3中使用hashlib模块进行md5操作 import hashlib # 待加密信息 str = 'asdas89799,.//plrmf' # 创建md5对象 hl = hashlib.md5() # Tips # 此处必须声明encode # 若写法为

    python接口自动化测试二十七:密码MD5加密   ''' MD5加密 '''# 由于MD5模块在python3中被移除# 在python3中使用hashlib模块进行md5操作import has ...

  2. Python之数据加密与解密及相关操作(hashlib模块、hmac模块、random模块、base64模块、pycrypto模块)

    本文内容 数据加密概述 Python中实现数据加密的模块简介 hashlib与hmac模块介绍 random与secrets模块介绍 base64模块介绍 pycrypto模块介绍 总结 参考文档 提 ...

  3. python---基础知识回顾(四)(模块sys,os,random,hashlib,re,序列化json和pickle,xml,shutil,configparser,logging,datetime和time,其他)

    前提:dir,__all__,help,__doc__,__file__ dir:可以用来查看模块中的所有特性(函数,类,变量等) >>> import copy >>& ...

  4. python 常用模块 time random os模块 sys模块 json & pickle shelve模块 xml模块 configparser hashlib subprocess logging re正则

    python 常用模块 time random os模块 sys模块 json & pickle shelve模块 xml模块 configparser hashlib  subprocess ...

  5. python基础语法11 内置模块time,datatime,random,os,sys,hashlib模块

    time模块 在python的三种时间表现形式: 1.时间戳: 给电脑看的. - 自1970-01-01 00:00:00到当前时间,按秒计算,计算了多少秒. 2.格式化时间(Format Strin ...

  6. time模块 datetime 模块 random 模块 OS 模块 sys 模块 hashlib 模块

    time模块 在python中的时间表现形式: 时间戳 (自1970-01-01-00-00 到当前时间,按秒计算,一共过了多少秒 格式化时间 返回的是时间的字符串 格式化时间对象 返回的是一个元组  ...

  7. Py修行路 python基础 (二十)模块 time模块,random模块,hashlib模块,OS及sys模块

    一.前提介绍: 可以开辟作用域的只有类,函数,和模块            for循环 if,else: 不能开辟自己的作用域 避免程序复用和重复调用,将这些写到一个.py文件中,做成一个模块,进行调 ...

  8. Python3 os模块&sys模块&hashlib模块

    ''' os模块 非常重要的模块 ''' import os # print(os.getcwd()) # 获取当前工作目录 # os.chdir(r'路径名') # 改变当前工作目录 # print ...

  9. python3.7 random模块

    #!/usr/bin/env python __author__ = "lrtao2010" #python3.7 random模块 import random #随机模块 # r ...

  10. day13 函数模块之序列化 random 模块 os模块 sys模块 hashlib模块 collections模块

    json import json dic = {'k1':'v1','k2':'v2','k3':'v3'} str_dic = json.dumps(dic) #序列化:将一个字典转换成一个字符串 ...

随机推荐

  1. 第二十三篇 logging模块(******)

    日志非常重要,而且非常常用,可以通过logging模块实现. 热身运动 import logging logging.debug("debug message") logging. ...

  2. sed-awk命令详解

      第2章 ***********sed***********. 1目  录 2.1 -------sed命令小结及小结图---- 1 2.2 -------第几行---------- 2 2.3 - ...

  3. ng2模板语法/内置指令速查表

    https://www.angular.cn/docs/ts/latest/guide/cheatsheet.html

  4. STL中list的erase()方法

    http://www.cnblogs.com/gshlsh17/ rase()方法是删除iterator指定的节点  但是要注意的是在执行完此函数的时候iterator也被销毁了   这样的话关于it ...

  5. (转)Loadrunner监控Linux的17个指标

    1.Average load:Average number of processes simultaneously in Ready state during the last minute.   上 ...

  6. stap中的entry函数

    只有在ret probe函数中,在这个函数中才会使用@entry函数去提取变量 是因为ret probe 有什么特殊的吗?在中间这个变量会变化吗? A new operator, @entry, is ...

  7. SpringBoot2.0

    建立可执行的Jars和Wars bootJar用于构建可执行的Jar: bootWar用于构建可执行的war. application.properties 不启动web服务器 spring.main ...

  8. jquery/js iframe 元素操作

    1.判断id/ class 是否存在? <script> $(function(){ if(("#id_name").length()>0){ //如果id 存在 ...

  9. [洛谷P3834] 【模板】可持久化线段树 1(主席树)

    题目大意:静态区间第K小 题解:主席树 卡点:无 C++ Code: #include <cstdio> #include <algorithm> #define maxn 2 ...

  10. wmic的用法

    原始文章链接:http://blog.sina.com.cn/s/blog_5fb265c70100w4d0.html 一.wmic的基本命令格式简析 经常看网上的相关资料的话,读者可能会对wmic有 ...