Python bsddb

来自开放百科 - 灰狐
跳转到: 导航, 搜索

Hash, BTree and Record Objects

http://docs.huihoo.com/python/2.5/lib/bsddb-objects.html

Example

>>> import bsddb
>>> db = bsddb.btopen('/tmp/spam.db', 'c') // create db in c:\tmp\spam.db or /tmp/spam.db
>>> for i in range(10): db['%d'%i] = '%d'% (i*i)
... 
>>> db['3']
'9'
>>> db.keys()
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
>>> db.first()
('0', '0')
>>> db.next()
('1', '1')
>>> db.last()
('9', '81')
>>> db.set_location('2')
('2', '4')
>>> db.previous() 
('1', '1')
>>> for k, v in db.iteritems():
...     print k, v
0 0
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
>>> '8' in db
True
>>> db.sync()
0
>>> db.clear()
>>> db.sync()
>>> db.keys()
[]

>>> for i in range(100000): db['%d'%i] = '%d'% (i*i) // 100,000 records, 5,040 KB size
>>> db['99999']
'9999800001'

Web Example

分享您的观点
个人工具
名字空间

变换
操作
导航
工具箱