Python 操作BDB (1)

Python 对BDB的访问支持的非常好,在内建的lib里就有对BDB的访问支持,

见博文 http://gashero.yeax.com/?p=5#id14

 

我简单写了个K-v的例子,记录如下:

 

'''
Created on 2009-9-13

@author: Administrator
'''
import bsddb  
class BDBTest(object):

    def __init__(self):

        self.db = bsddb.btopen('test.db', 'c')
        print "Opened"
        self.db["2009-08-14 22:00"] = "gg"
        self.db["2009-08-15 22:00"] = "cc"
        self.db["2009-07-15 00:00"] = "tt"
        self.db["2009-08-16 22:00"] = "gg"
        self.db["2009-08-16 23:00"] = "gx"
        # K-V
        print self.db["2009-08-14 22:00"]
        # Use Previous and next allocate the cursor
        self.db.set_location('2009-08-15')
        # 
        print self.db.next()
        
        print self.db.previous() 
        
        #d = bsddb.hashopen("aaa.db", "c")
        
if __name__ == '__main__':
    try:
        bdb = BDBTest()
    except:
        print "Exception Happen"
 

在接下来的系列里,还会对BDB的的访问方式进行进一步的探究。

 

你可能感兴趣的:(C++,c,python,C#)