O'Reilly logo

Python: Essential Reference, Third Edition by David Beazley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required