pickle模块的使用

import pickle
import string

class TestA:
    def __init__(self):
        self.a = 11
        self.b = 33

    def set(self, v):
        self.a = v        
    
    def __str__(self):
        return "%d %d" % (self.a, self.b)
        


a = TestA()
print a
a.set(100)
print a

f = open("111.dmp", "w")
pickle.dump(a, f)
f.close()

print '-'*60

f = open("111.dmp", "r")
ld = pickle.load(f)
f.close()
print ld

 

你可能感兴趣的:(F#)