python shelve模块,pythonshelve,[Python]代码de


[Python]代码

def CreateData():       try:           db = shelve.open('db.dat', 'c')           # key与value必须是字符串           db['int'] = 1          db['float'] = 2.3          db['string'] = "I like python."          db['key'] = 'value'      finally:           db.close()   def LoadData():       db = shelve.open('db.dat', 'r')       for item in db.items():           print item       db.close()   if __name__ == '__main__':       CreateData()       LoadData()      import shelvedef CreateData():    try:        db = shelve.open('db.dat', 'c')        # key与value必须是字符串        db['int'] = 1        db['float'] = 2.3        db['string'] = "I like python."        db['key'] = 'value'    finally:        db.close()def LoadData():    db = shelve.open('db.dat', 'r')    for item in db.items():        print item    db.close()if __name__ == '__main__':    CreateData()    LoadData()

评论关闭