18 其他不常用模块
猴子补丁
import json
import ujson
def monkey_patch():
json.loads = ujson.loads
json.dumps = ujson.dumps
monkey_patch()
import shelve
f = shelve.open(r'sheve.txt')
f['stu1_info'] = {'name': 'EGON', 'age': 28, 'hobby': ['piao', 'smoking', 'drinking']}
f['stu2_info'] = {'name': 'gangdan', 'age': 53}
f['school_info'] = 123123123123123123123123123
f['test'] = {1,2,3,4,5}
f.close()
import shelve
f=shelve.open(r'sheve.txt')
print(f['stu1_info']['name'])
print(f['school_info'])
print(f['test'])
f.close()
import configparser
config = configparser.ConfigParser()
config.read('config.ini')
res = config.sections()
print(res)
res = config.options('section1')
print(res)
res = config.items('section1')
print(res)
res = config.get('section1','is_admin')
res = bool(res)
res = config.getboolean('section1','is_admin')
print(res,type(res))
res = config.get('section1','salary')
res = config.getfloat('section1','salary')
res = config.getint('section1','salary')
print(res,type(res))
hashlib
import hashlib
with open(r'D:\全栈18期\day17\视频\01 日志模块.mp4',mode='rb') as f:
m = hashlib.md5()
for line in f:
m.update(line)
print(m.hexdigest())
import hashlib