美文网首页
2020-05-07

2020-05-07

作者: 价值投机168 | 来源:发表于2020-05-08 11:07 被阅读0次

    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())
    

    相关文章

      网友评论

          本文标题:2020-05-07

          本文链接:https://www.haomeiwen.com/subject/umznghtx.html