import shelve
d = shelve.open(filename) # open, with (g)dbm filename -- no suffix
d[key] = data # store data at key (overwrites old data if
# using an existing key)
data = d[key] # retrieve a COPY of the data at key (raise
# KeyError if no such key) -- NOTE that this
# access returns a *copy* of the entry!
del d[key] # delete data stored at key (raises KeyError
# if no such key)
flag = d.has_key(key) # true if the key exists; same as "key in d"
list = d.keys() # a list of all existing keys (slow!)
d.close()
您可以使用书架库。从搁置文档:
“shelf”是一个持久的、类似字典的对象。与dbm数据库的区别在于值(而不是键!)工具架中可以是基本上任意的Python对象——“pickle”模块可以处理的任何对象
^{} 它:
pickle
模块允许您将大多数Python对象转储到一个文件中,然后再次读取它们。在SQLite公司。非常容易设置,您可以获得许多内置的数据库函数。您也不必处理文件读/写和解析。在
相关问题 更多 >
编程相关推荐