Movatterモバイル変換


[0]ホーム

URL:


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:7.12 bsddbUp:7.12 bsddbNext:7.13 zlib

 
7.12.1 Hash, BTree and Record Objects

Once instantiated, hash, btree and record objects support the followingmethods:

close()
Close the underlying file. The object can no longer be accessed. Sincethere is no openopen method for these objects, to open the fileagain a newbsddb module open function must be called.

keys()
Return the list of keys contained in the DB file. The order of the list isunspecified and should not be relied on. In particular, the order of thelist returned is different for different file formats.

has_key(key)
Return1 if the DB file contains the argument as a key.

set_location(key)
Set the cursor to the item indicated bykey and return a tuplecontaining the key and its value. For binary tree databases (openedusingbtopen()), ifkey does not actually exist inthe database, the cursor will point to the next item in sorted orderand return that key and value. For other databases,KeyError will be raised ifkey is not found in thedatabase.

first()
Set the cursor to the first item in the DB file and return it. The order of keys in the file is unspecified, except in the case of B-Tree databases.

next()
Set the cursor to the next item in the DB file and return it. The order of keys in the file is unspecified, except in the case of B-Tree databases.

previous()
Set the cursor to the first item in the DB file and return it. Theorder of keys in the file is unspecified, except in the case of B-Treedatabases. This is not supported on hashtable databases (those openedwithhashopen()).

last()
Set the cursor to the last item in the DB file and return it. Theorder of keys in the file is unspecified. This is not supported onhashtable databases (those opened withhashopen()).

sync()
Synchronize the database on disk.

Example:

>>> import bsddb>>> db = bsddb.btopen('/tmp/spam.db', 'c')>>> 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')>>> db.sync()0


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:7.12 bsddbUp:7.12 bsddbNext:7.13 zlib
Release 2.2.3, documentation updated on 30 May 2003.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2026 Movatter.jp