Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9cbf1c52
Commit
9cbf1c52
authored
Jul 17, 1997
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extensive changes by AMK.
parent
cf40d1b7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
154 additions
and
8 deletions
+154
-8
Doc/lib/libgdbm.tex
Doc/lib/libgdbm.tex
+77
-4
Doc/libgdbm.tex
Doc/libgdbm.tex
+77
-4
No files found.
Doc/lib/libgdbm.tex
View file @
9cbf1c52
\section
{
Built-in Module
\sectcode
{
gdbm
}}
\label
{
module-gdbm
}
\bimodindex
{
gdbm
}
This module is nearly identical to the
\code
{
dbm
}
module, but uses
GDBM instead. Its interface is identical, and not repeated here.
Warning: the file formats created by gdbm and dbm are incompatible.
This module is quite similar to the
\code
{
dbm
}
module, but uses
{
\sc
gdbm
}
instead to provide some additional functionality. Please note that
the file formats created by
{
\sc
gdbm
}
and dbm are incompatible.
\bimodindex
{
dbm
}
The
\code
{
gdbm
}
module provides an interface to the GNU DBM
library.
{
\sc
gdbm
}
objects behave like mappings
(dictionaries), except that keys and values are always strings.
Printing a
{
\sc
gdbm
}
object doesn't print the keys and values, and the
\code
{
items()
}
and
\code
{
values()
}
methods are not supported.
The module defines the following constant and functions:
\renewcommand
{
\indexsubitem
}{
(in module dbm)
}
\begin{excdesc}
{
error
}
Raised on dbm-specific errors, such as I/O errors.
\code
{
KeyError
}
is
raised for general mapping errors like specifying an incorrect key.
\end{excdesc}
\begin{funcdesc}
{
open
}{
filename
\,
\optional
{
flag
\,
\optional
{
mode
}}}
Open a dbm database and return a dbm object. The
\var
{
filename
}
argument is the name of the database file (without the
\file
{
.dir
}
or
\file
{
.pag
}
extensions).
The optional
\var
{
flag
}
argument can be
\code
{
'r'
}
(to open an existing database for reading only --- default),
\code
{
'w'
}
(to open an existing database for reading and writing),
\code
{
'c'
}
(which creates the database if it doesn't exist), or
\code
{
'n'
}
(which always creates a new empty database).
Appending
\code
{
f
}
to the flag opens the database in fast mode;
altered data will not automatically be written to the disk after every
change. This results in faster writes to the database, but may result
in an inconsistent database if the program crashes while the database
is still open. Use the
\code
{
sync()
}
method to force any unwritten
data to be written to the disk.
The optional
\var
{
mode
}
argument is the
\UNIX
{}
mode of the file, used
only when the database has to be created. It defaults to octal
\code
{
0666
}
.
\end{funcdesc}
In addition to the dictionary-like methods,
{
\sc
gdbm
}
objects have the
following methods:
\begin{funcdesc}
{
firstkey
}{}
It's possible to loop over every key in the database using this method
and the
\code
{
nextkey()
}
method. The traversal is ordered by
{
\sc
gdbm
}
's
internal hash values, and won't be sorted by the key values. This
method returns the starting key.
\end{funcdesc}
\begin{funcdesc}
{
nextkey
}{
key
}
Returns the key that follows
\var
{
key
}
in the traversal. The
following code prints every key in the database
\code
{
db
}
, without having to
create a list in memory that contains them all:
\bcode
\begin{verbatim}
k=db.firstkey()
while k!=None:
print k
k=db.nextkey(k)
\end{verbatim}
\ecode
\end{funcdesc}
\begin{funcdesc}
{
reorganize
}{}
If you have carried out a lot of deletions and would like to shrink
the space used by the
{
\sc
gdbm
}
file, this routine will reorganize the
database.
{
\sc
gdbm
}
will not shorten the length of a database file except
by using this reorganization; otherwise, deleted file space will be
kept and reused as new (key,value) pairs are added.
\end{funcdesc}
\begin{funcdesc}
{
sync
}{}
When the database has been opened in fast mode, this method forces any
unwritten data to be written to the disk.
\end{funcdesc}
Doc/libgdbm.tex
View file @
9cbf1c52
\section
{
Built-in Module
\sectcode
{
gdbm
}}
\label
{
module-gdbm
}
\bimodindex
{
gdbm
}
This module is nearly identical to the
\code
{
dbm
}
module, but uses
GDBM instead. Its interface is identical, and not repeated here.
Warning: the file formats created by gdbm and dbm are incompatible.
This module is quite similar to the
\code
{
dbm
}
module, but uses
{
\sc
gdbm
}
instead to provide some additional functionality. Please note that
the file formats created by
{
\sc
gdbm
}
and dbm are incompatible.
\bimodindex
{
dbm
}
The
\code
{
gdbm
}
module provides an interface to the GNU DBM
library.
{
\sc
gdbm
}
objects behave like mappings
(dictionaries), except that keys and values are always strings.
Printing a
{
\sc
gdbm
}
object doesn't print the keys and values, and the
\code
{
items()
}
and
\code
{
values()
}
methods are not supported.
The module defines the following constant and functions:
\renewcommand
{
\indexsubitem
}{
(in module dbm)
}
\begin{excdesc}
{
error
}
Raised on dbm-specific errors, such as I/O errors.
\code
{
KeyError
}
is
raised for general mapping errors like specifying an incorrect key.
\end{excdesc}
\begin{funcdesc}
{
open
}{
filename
\,
\optional
{
flag
\,
\optional
{
mode
}}}
Open a dbm database and return a dbm object. The
\var
{
filename
}
argument is the name of the database file (without the
\file
{
.dir
}
or
\file
{
.pag
}
extensions).
The optional
\var
{
flag
}
argument can be
\code
{
'r'
}
(to open an existing database for reading only --- default),
\code
{
'w'
}
(to open an existing database for reading and writing),
\code
{
'c'
}
(which creates the database if it doesn't exist), or
\code
{
'n'
}
(which always creates a new empty database).
Appending
\code
{
f
}
to the flag opens the database in fast mode;
altered data will not automatically be written to the disk after every
change. This results in faster writes to the database, but may result
in an inconsistent database if the program crashes while the database
is still open. Use the
\code
{
sync()
}
method to force any unwritten
data to be written to the disk.
The optional
\var
{
mode
}
argument is the
\UNIX
{}
mode of the file, used
only when the database has to be created. It defaults to octal
\code
{
0666
}
.
\end{funcdesc}
In addition to the dictionary-like methods,
{
\sc
gdbm
}
objects have the
following methods:
\begin{funcdesc}
{
firstkey
}{}
It's possible to loop over every key in the database using this method
and the
\code
{
nextkey()
}
method. The traversal is ordered by
{
\sc
gdbm
}
's
internal hash values, and won't be sorted by the key values. This
method returns the starting key.
\end{funcdesc}
\begin{funcdesc}
{
nextkey
}{
key
}
Returns the key that follows
\var
{
key
}
in the traversal. The
following code prints every key in the database
\code
{
db
}
, without having to
create a list in memory that contains them all:
\bcode
\begin{verbatim}
k=db.firstkey()
while k!=None:
print k
k=db.nextkey(k)
\end{verbatim}
\ecode
\end{funcdesc}
\begin{funcdesc}
{
reorganize
}{}
If you have carried out a lot of deletions and would like to shrink
the space used by the
{
\sc
gdbm
}
file, this routine will reorganize the
database.
{
\sc
gdbm
}
will not shorten the length of a database file except
by using this reorganization; otherwise, deleted file space will be
kept and reused as new (key,value) pairs are added.
\end{funcdesc}
\begin{funcdesc}
{
sync
}{}
When the database has been opened in fast mode, this method forces any
unwritten data to be written to the disk.
\end{funcdesc}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment