/Doc/library/dbm.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 78 lines · 54 code · 24 blank · 0 comment · 0 complexity · 3b3515871b0f6cc9674a548e426673fc MD5 · raw file

  1. :mod:`dbm` --- Simple "database" interface
  2. ==========================================
  3. .. module:: dbm
  4. :platform: Unix
  5. :synopsis: The standard "database" interface, based on ndbm.
  6. .. note::
  7. The :mod:`dbm` module has been renamed to :mod:`dbm.ndbm` in Python 3.0. The
  8. :term:`2to3` tool will automatically adapt imports when converting your
  9. sources to 3.0.
  10. The :mod:`dbm` module provides an interface to the Unix "(n)dbm" library. Dbm
  11. objects behave like mappings (dictionaries), except that keys and values are
  12. always strings. Printing a dbm object doesn't print the keys and values, and the
  13. :meth:`items` and :meth:`values` methods are not supported.
  14. This module can be used with the "classic" ndbm interface, the BSD DB
  15. compatibility interface, or the GNU GDBM compatibility interface. On Unix, the
  16. :program:`configure` script will attempt to locate the appropriate header file
  17. to simplify building this module.
  18. The module defines the following:
  19. .. exception:: error
  20. Raised on dbm-specific errors, such as I/O errors. :exc:`KeyError` is raised for
  21. general mapping errors like specifying an incorrect key.
  22. .. data:: library
  23. Name of the ``ndbm`` implementation library used.
  24. .. function:: open(filename[, flag[, mode]])
  25. Open a dbm database and return a dbm object. The *filename* argument is the
  26. name of the database file (without the :file:`.dir` or :file:`.pag` extensions;
  27. note that the BSD DB implementation of the interface will append the extension
  28. :file:`.db` and only create one file).
  29. The optional *flag* argument must be one of these values:
  30. +---------+-------------------------------------------+
  31. | Value | Meaning |
  32. +=========+===========================================+
  33. | ``'r'`` | Open existing database for reading only |
  34. | | (default) |
  35. +---------+-------------------------------------------+
  36. | ``'w'`` | Open existing database for reading and |
  37. | | writing |
  38. +---------+-------------------------------------------+
  39. | ``'c'`` | Open database for reading and writing, |
  40. | | creating it if it doesn't exist |
  41. +---------+-------------------------------------------+
  42. | ``'n'`` | Always create a new, empty database, open |
  43. | | for reading and writing |
  44. +---------+-------------------------------------------+
  45. The optional *mode* argument is the Unix mode of the file, used only when the
  46. database has to be created. It defaults to octal ``0666`` (and will be
  47. modified by the prevailing umask).
  48. .. seealso::
  49. Module :mod:`anydbm`
  50. Generic interface to ``dbm``\ -style databases.
  51. Module :mod:`gdbm`
  52. Similar interface to the GNU GDBM library.
  53. Module :mod:`whichdb`
  54. Utility module used to determine the type of an existing database.