| raised for general mapping errors like specifying an incorrect key. |
| |
| |
| .. function:: open(filename, [flag, [mode]]) |
| |
| Open a ``gdbm`` database and return a ``gdbm`` object. The *filename* argument |
| is the name of the database file. |
| |
n | The optional *flag* argument can be ``'r'`` (to open an existing database for |
n | The optional *flag* argument can be: |
| reading only --- default), ``'w'`` (to open an existing database for reading and |
| writing), ``'c'`` (which creates the database if it doesn't exist), or ``'n'`` |
| (which always creates a new empty database). |
| |
n | The following additional characters may be appended to the flag to control how |
n | +---------+-------------------------------------------+ |
| the database is opened: |
| | Value | Meaning | |
| +=========+===========================================+ |
| | ``'r'`` | Open existing database for reading only | |
| | | (default) | |
| +---------+-------------------------------------------+ |
| | ``'w'`` | Open existing database for reading and | |
| | | writing | |
| +---------+-------------------------------------------+ |
| | ``'c'`` | Open database for reading and writing, | |
| | | creating it if it doesn't exist | |
| +---------+-------------------------------------------+ |
| | ``'n'`` | Always create a new, empty database, open | |
| | | for reading and writing | |
| +---------+-------------------------------------------+ |
| |
n | * ``'f'`` --- Open the database in fast mode. Writes to the database will not |
n | The following additional characters may be appended to the flag to control |
| be synchronized. |
| how the database is opened: |
| |
n | +---------+--------------------------------------------+ |
| | Value | Meaning | |
| +=========+============================================+ |
| | ``'f'`` | Open the database in fast mode. Writes | |
| | | to the database will not be synchronized. | |
| +---------+--------------------------------------------+ |
| * ``'s'`` --- Synchronized mode. This will cause changes to the database will be |
| | ``'s'`` | Synchronized mode. This will cause changes | |
| immediately written to the file. |
| | | to the database to be immediately written | |
| |
| | | to the file. | |
| * ``'u'`` --- Do not lock database. |
| +---------+--------------------------------------------+ |
| | ``'u'`` | Do not lock database. | |
| +---------+--------------------------------------------+ |
| |
| Not all flags are valid for all versions of ``gdbm``. The module constant |
t | ``open_flags`` is a string of supported flag characters. The exception |
t | :const:`open_flags` is a string of supported flag characters. The exception |
| :exc:`error` is raised if an invalid flag is specified. |
| |
| The optional *mode* argument is the Unix mode of the file, used only when the |
| database has to be created. It defaults to octal ``0666``. |
| |
| In addition to the dictionary-like methods, ``gdbm`` objects have the following |
| methods: |
| |