python-常用模块
random
随机数
randint 随机整数
random.random() 随机0-1的小数
sample() 随机抽n个
shuffle() 打乱
time
时间
sleep() 睡眠
time() 时间戳
striftime('%Y-%m-%d %H:%M:%S') 格式化时间
将数字转换结构化时间
t1 = time.localtime(1323288)
转换格式化时间
time.striftime('%Y-%m-%d %H:%M:%S',t1)
os
os.makedirs 创建多级目录
makedir 创建单一文件
os.remove()
os.rename()
os.listdir() 列出指定目录下的所有的文件名
os.path
join() 路径拼接
exists() 判断是否存在文件
getSize() 文件大小
collections 容器集合
counter 计数器
sys
sys.argv 接收命令行参数
sys.path 模块的搜索路径
sys.module 当前已经被引入到内存的模块
json pickle
序列化:
把对象成bytes
dump load 文件相关
dumps 序列化 loads 反序列化 对象
logging
hashlib 加密 盐不要动
obj = hashlib.md5('加盐',encode('utf-8))
obj.update('密码',encode('utf-8))
s = obj.hexdigest()
print(s)
re 正则表示式
. 除了换行什么都要
\w 数字字母下划线
\d 数字
^ $ 以什么开头,什么结尾
| 或
() 分组
[...]
量词 * + ? {n,m}
贪婪匹配非贪婪匹配
.* .*?
findall()
search() 匹配到第一个内容就返回
match() 匹配到第一个内容就返回 从头开始

浙公网安备 33010602011771号