Python 百分号编码、解码
from urllib.parse import quote, unquote
name = "王者荣耀"
print(quote(name)) # %E7%8E%8B%E8%80%85%E8%8D%A3%E8%80%80
print(unquote("%E7%8E%8B%E8%80%85%E8%8D%A3%E8%80%80")) # 王者荣耀
Python哈希摘要
from hashlib import md5, sha256
hasher = md5('123456'.encode())
print(hasher.hexdigest())
# 文件生成 哈希摘要
with open("a.txt", "rb") as file:
hasher = md5(file.read())
print(hasher.hexdigest())
hasher = md5()
with open("a.txt", "rb") as file:
# 使用迭代器读取文件,避免文件一次性加载到内存
file_iter = iter(lambda: file.read(512), b'')
for data in file_iter:
hasher.update(data)
print(hasher.hexdigest())
594

被折叠的 条评论
为什么被折叠?



