1 导入模块
- pickle模块适用Python中所有数据类型
import pickle
import time
2 数据类型转二进制文件
structTime = time.localtime(time.time())
with open('structTime.txt', 'wb') as file:
pickle.dump(structTime, file)
3 二进制文件转数据类型
with open('structTime.txt', 'rb') as file:
structTime = pickle.load(file)
print(structTime)
4 数据类型转二进制
string = pickle.dumps(structTime)
print(type(string))
5 二进制转数据类型
structTime = pickle.loads(string)
print(type(structTime))