Skip to Content
Python: Essential Reference, Third Edition
book

Python: Essential Reference, Third Edition

by David Beazley
February 2006
Intermediate to advanced content levelIntermediate to advanced
648 pages
14h 53m
English
Sams
Content preview from Python: Essential Reference, Third Edition

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python: Essential Reference

Python: Essential Reference

David M. Beazley

Publisher Resources

ISBN: 0672328623Purchase book