Python——pickle Python pickle 关于pickle模块 Python的一个序列化与反序列化模块,支持Python基本数据类型 可以处理自定义的类对象,方法等 内存中使用123456789101112131415161718192021import pickleorigin = [1, 2, 3, [4, 5, 6]]print "origin: %s" % origintemp = pickle.dumps(origin)print "temp: %s" % tempnew = pickle.loads(temp)print "new: %s" % new## output:# origin: [1, 2, 3, [4, 5, 6]]# temp: (lp0# I1# aI2# aI3# a(lp1# I4# aI5# aI6# aa.# new: [1, 2, 3, [4, 5, 6]] 硬盘中使用12345678910111213import pickleorigin = [1, 2, 3, [4, 5, 6]]print "origin: %s" % origin# open a binary and write the resultpickle.dump(origin, open('temp', 'wb'))# open a binary and read the original objectnew = pickle.load(open('temp', 'rb'))print "new: %s" % new## output# origin: [1, 2, 3, [4, 5, 6]]# new: [1, 2, 3, [4, 5, 6]]