File: table.py

package info (click to toggle)
python-agate-dbf 0.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 192 kB
  • sloc: makefile: 126; python: 106
file content (26 lines) | stat: -rw-r--r-- 655 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python

"""
This module contains the DBF extension to :class:`Table <agate.table.Table>`.
"""

import agate
from dbfread import DBF

def recfactory(items):
    return tuple(kv[1] for kv in items)

def from_dbf(cls, path, encoding=None):
    """
    Parse a DBF file.

    :param path:
        Path to an DBF file to load. Note that due to limitations of the
        dependency you can not pass a file handle. It must be a path.
    """
    dbf = DBF(path, load=True, encoding=encoding, recfactory=recfactory)
    table = agate.Table(dbf.records, column_names=dbf.field_names)

    return table

agate.Table.from_dbf = classmethod(from_dbf)