EcohydroLib
1.29
|
Methods for reading and write DBF data files. More...
Functions | |
def | dbfreader (f) |
Returns an iterator over records in a Xbase DBF file. More... | |
def | dbfwriter (f, fieldnames, fieldspecs, records) |
Return a string suitable for writing directly to a binary dbf file. More... | |
Variables | |
string | filename = '/pydev/databases/orders.dbf' |
tuple | f = open(filename, 'rb') |
tuple | db = list(dbfreader(f)) |
list | records = [rec[1:] for rec in records] |
Methods for reading and write DBF data files.
Adapted from: http://code.activestate.com/recipes/362715-dbf-reader-and-writer/
This software is provided free of charge under the New BSD License. Please see the following license information:
Copyright (c) 2013, University of North Carolina at Chapel Hill All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
def ecohydrolib.dbf.dbfreader | ( | f | ) |
Returns an iterator over records in a Xbase DBF file.
f | A file descriptor |
The first row returned contains the field names. The second row contains field specs: (type, size, decimal places). Subsequent rows contain the data records. If a record is marked as deleted, it is skipped.
File should be opened for binary reads.
def ecohydrolib.dbf.dbfwriter | ( | f, | |
fieldnames, | |||
fieldspecs, | |||
records | |||
) |
Return a string suitable for writing directly to a binary dbf file.
f | File descriptor, should be open for writing in a binary mode. |
fieldnames | List of field names, should be no longer than ten characters and not include . |
fieldspecs | List of field specifications, in the form (type, size, deci) where type is one of: C for ascii character data M for ascii character memo data (real memo fields not supported) D for datetime objects N for ints or decimal objects L for logical values 'T', 'F', or '?' size is the field width deci is the number of decimal places in the provided decimal object |
records | An iterable over the records (sequences of field values). |
tuple ecohydrolib.dbf.f = open(filename, 'rb') |
list ecohydrolib.dbf.filename = '/pydev/databases/orders.dbf' |
list ecohydrolib.dbf.records = [rec[1:] for rec in records] |