Introduction

Most of the databases in this chapter are opened using a variation of the open() function (defined in each database module):

open(filename [,flag [, mode ]])

This function opens the database file filename and returns a database object. flag is ‘r’ for read-only access, ‘w’ for read-write access, ‘c’ to create the database if it doesn’t exist, or ‘n’ to force the creation of a new database. mode is the integer file-access mode used when creating the database (the default is 0666 on UNIX).

The object returned by the open() function supports the following dictionary-like operations:

OperationDescription
d[key] = valueInserts value into the database
value = d[key]Gets data from the database
del d[key]Removes a database entry
d.close()Closes ...

Get Python: Essential Reference, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.