ship.utils.dbfread package¶
Submodules¶
ship.utils.dbfread.dbf module¶
Class to read DBF files.
-
class
DBF
(filename, encoding=None, ignorecase=True, lowernames=False, parserclass=<class 'ship.utils.dbfread.field_parser.FieldParser'>, recfactory=<class 'collections.OrderedDict'>, load=False, raw=False, ignore_missing_memofile=False)[source]¶ Bases:
object
DBF table.
-
dbversion
¶
-
deleted
¶ Deleted records. When loaded a list of records, when not loaded a new
RecordIterator
object.
-
load
()[source]¶ Load records into memory.
This loads both records and deleted records. The
records
anddeleted
attributes will now be lists of records.
-
loaded
¶ True
if records are loaded into memory.
-
records
¶ Records (not included deleted ones). When loaded a list of records, when not loaded a new
RecordIterator
object.
-
ship.utils.dbfread.dbversions module¶
Based on the list found here:
ship.utils.dbfread.deprecated_dbf module¶
-
class
DeprecatedDBF
(filename, encoding=None, ignorecase=True, lowernames=False, parserclass=<class 'ship.utils.dbfread.field_parser.FieldParser'>, recfactory=<class 'collections.OrderedDict'>, load=False, raw=False, ignore_missing_memofile=False)[source]¶ Bases:
ship.utils.dbfread.dbf.DBF
,list
This is the old version of the table which is a subclass of list.
It is included for backwards compatability with 1.0 and older.
-
loaded
¶
-
ship.utils.dbfread.exceptions module¶
ship.utils.dbfread.field_parser module¶
Parser for DBF fields.
-
class
FieldParser
(table, memofile=None)[source]¶ Bases:
object
-
field_type_supported
(field_type)[source]¶ Checks if the field_type is supported by the parser
field_type should be a one-character string like ‘C’ and ‘N’. Returns a boolen which is True if the field type is supported.
-
parse2B
(field, data)¶ Parse integer or autoincrement field and return int.
-
parse40
(field, data)¶ Parse time field (T)
Returns datetime.datetime or None
-
parseB
(field, data)[source]¶ Binary memo field or double precision floating point number
dBase uses B to represent a memo index (10 bytes), while Visual FoxPro uses it to store a double precision floating point number (8 bytes).
-
parseG
(field, data)[source]¶ OLE Object stored in memofile.
The raw data is returned as a binary string.
-
parseM
(field, data)[source]¶ Parse memo field (M, G, B or P)
Returns memo index (an integer), which can be used to look up the corresponding memo in the memo file.
-
parseN
(field, data)[source]¶ Parse numeric field (N)
Returns int, float or None if the field is empty.
-
ship.utils.dbfread.ifiles module¶
Functions for dealing with mixed-case files from case-preserving file systems.
Todo
- handle patterns that already have brackets
ship.utils.dbfread.memo module¶
Reads data from FPT (memo) files.
FPT files are used to varying lenght text or binary data which is too large to fit in a DBF field.
VFP == Visual FoxPro DB3 == dBase III DB4 == dBase IV
-
class
DB3MemoFile
(filename)[source]¶ Bases:
ship.utils.dbfread.memo.MemoFile
dBase III memo file.
-
class
DB4MemoFile
(filename)[source]¶ Bases:
ship.utils.dbfread.memo.MemoFile
dBase IV memo file
ship.utils.dbfread.struct_parser module¶
Parser that converts (C style) binary structs named tuples.
The struct can be read from a file or a byte string.
ship.utils.dbfread.test_field_parser module¶
ship.utils.dbfread.test_ifiles module¶
ship.utils.dbfread.test_read_and_length module¶
Tests reading from database.
Module contents¶
Read DBF files with Python.
Example
>>> from dbfread import DBF
>>> for record in DBF('people.dbf'):
... print(record)
OrderedDict([('NAME', 'Alice'), ('BIRTHDATE', datetime.date(1987, 3, 1))])
OrderedDict([('NAME', 'Bob'), ('BIRTHDATE', datetime.date(1980, 11, 12))])
Full documentation at http://dbfread.readthedocs.org/