2020-05-07
2020-05-08 本文已影响0人
价值投机168
1.持久化:
image.png
2.pickle:
image.png
3.举例:
from person import Person,Manager
bob=Person('Bob Smith')
sue=Person('Sue Jones','dev',10000)
tom=Manager('Tom Jones',5000)
import shelve
db = shelve.open('persondb')
for obj in (bob,sue,tom):
db[obj.name] = obj
db.close()
if name=='main':
db=shelve.open('persondb')
for key in sorted(db):
print(key,'=>',db[key])
bob1 = db['Bob Smith']
print(bob1.lastName())