Dbase / foxpro files

Discussion in 'Python' started by Johny, May 15, 2008.

  1. Johny

    Johny Guest

    Is there a module for reading/modifing db files from Python?
    Thanks for help
    B.
     
    Johny, May 15, 2008
    #1
    1. Advertising

  2. Johny

    Peter Otten Guest

    Peter Otten, May 15, 2008
    #2
    1. Advertising

  3. Johny

    John Machin Guest

    Johny wrote:
    > Is there a module for reading/modifing db files from Python?
    > Thanks for help
    > B.


    I have a module -- which I'm going to get around to releasing one of
    these days :) -- which allows to read dBase III, dBase IV and Foxpro
    files (sequentially only, not randomly) and to write dBaseIII files
    sequentially. Index files if any are ignored.

    Field types supported for reading:
    C character
    D date
    F float
    I integer (32 bits)
    L logical
    M memo (stored in a .DBT (dBase) or .FPT (FoxPro) file)
    N number
    T time

    Writing supports only dBaseIII with C, D, L and N fields, but could be
    extended easily enough (I've never had the need). No index files are
    written.

    E-mail me if you are interested.

    Cheers,
    John
     
    John Machin, May 15, 2008
    #3
  4. Johny

    Johny Guest

    On May 15, 5:21 pm, John Machin <> wrote:
    > Johny wrote:
    > > Is there a module for reading/modifing db files from Python?
    > > Thanks for help
    > > B.

    >
    > I have a module -- which I'm going to get around to releasing one of
    > these days :) -- which allows to read dBase III, dBase IV and Foxpro
    > files (sequentially only, not randomly) and to write dBaseIII files
    > sequentially. Index files if any are ignored.
    >
    > Field types supported for reading:
    > C character
    > D date
    > F float
    > I integer (32 bits)
    > L logical
    > M memo (stored in a .DBT (dBase) or .FPT (FoxPro) file)
    > N number
    > T time
    >
    > Writing supports only dBaseIII with C, D, L and N fields, but could be
    > extended easily enough (I've never had the need). No index files are
    > written.
    >
    > E-mail me if you are interested.
    >
    > Cheers,
    > John


    Hello John,
    Yes, I am interested. Is it possible to download the module?
    Thanks
    Lad
     
    Johny, May 15, 2008
    #4
  5. Johny ha scritto:
    > Is there a module for reading/modifing db files from Python?
    > Thanks for help
    > B.


    If your target is Windows, you can try mediator components

    http://www.otc.pl/download/

    which are COM objects based on xHarbour and which give you
    full access to DBF and index.

    You need PythonWin too.

    I did some tests, if you like i can send you something,
    call me in my private mail.

    Claudio
     
    Claudio Driussi, May 15, 2008
    #5
  6. Johny

    Guest

  7. Johny

    Ethan Furman Guest

    Johny wrote:

    >Is there a module for reading/modifing db files from Python?
    >Thanks for help
    >B.
    >--
    >http://mail.python.org/mailman/listinfo/python-list
    >
    >

    I'm switching my company's software base over from FoxPro 6 to Python.
    As part of that effort I have written (and am still enhancing :) a
    dbf.py module which reads/writes both dBase III and FoxPro tables.

    Index files are not supported, but the table can be sorted by any
    combination of fields after being opened.

    dBase III table/memo support is complete, but FoxPro field types
    Currency, Double, General, and Picture are not supported and those
    fields are stripped out when opened, and will not be in any saved
    version of that table. At this point, the dbf file itself is read into
    memory, all updates are held in memory, and the table is only written to
    disk when the Save method is called.

    Record navigation can be sequential or random, and Top, Bottom, Next,
    and Previous are supported.

    Searching is supported, using (or not) deleted records is supported,
    adding and deleting fields is supported, saving as a csv file, and more.

    Let me know if you'd like the module. Hope this helps.

    Sample session follows...

    >>> import dbf
    >>> table = dbf.DbfTable('newtable','name C(10), age N(3.0), wisdom M')
    >>> print table


    Table: newtable.dbf
    Type: dBase III Plus
    Last updated: 2008-05-16
    Record count: 0
    Field count: 3
    Record length: 24

    --Fields--
    name C(10)
    age N(3.0)
    wisdom M(10)

    >>> table.Append()
    >>> table.name = 'Ethan'
    >>> table.age = 37
    >>> table.wisdom = 'Python rules!'
    >>> table.Scatter()

    {'age': 37, 'name': 'Ethan', 'wisdom': 'Python rules!'}
    >>> table.GetField('name')

    'Ethan'
    >>> table[0]

    Ethan 37 1
    >>> record = table[0]
    >>> record.name

    'Ethan'
    >>> record.wisdom

    'Python rules!'
    >>> record.age = 40
    >>> record

    Ethan 40 1
    >>> table[0]

    Ethan 40 1
    >>> table.Append({'name':'Lori', 'age':45, 'wisdom':'happy gardens make

    a happy wife'})
    >>> table.Scatter()

    {'age': 45, 'name': 'Lori', 'wisdom': 'happy gardens make a happy wife'}
    >>> for record in table:

    .... print record.name, record.wisdom
    ....
    Ethan Python rules!
    Lori happy gardens make a happy wife
    >>>
     
    Ethan Furman, May 16, 2008
    #7
  8. Johny

    Johny Guest

    Thanks for your reply.Is it possible to delete a record by using the
    module?
    Thanks
    L>
     
    Johny, May 17, 2008
    #8
  9. Johny

    Ethan Furman Guest

    Johny wrote:

    >Thanks for your reply.Is it possible to delete a record by using the
    >module?
    >Thanks
    >L>
    >--
    >http://mail.python.org/mailman/listinfo/python-list
    >
    >

    It is possible with mine. To clarify an earlier post, my module is for
    dBase III and VFP 6.0 files only (those were the only two I needed :).

    Hope this helps.
    --
    Ethan
     
    Ethan Furman, May 19, 2008
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stan Cook

    Working with dbase files

    Stan Cook, Feb 28, 2005, in forum: Python
    Replies:
    3
    Views:
    292
    Larry Bates
    Feb 28, 2005
  2. Durumdara
    Replies:
    1
    Views:
    378
    Larry Bates
    Feb 7, 2006
  3. Ethan Furman

    dBase III files and Visual Foxpro 6 files

    Ethan Furman, Dec 8, 2008, in forum: Python
    Replies:
    4
    Views:
    892
    imageguy
    Dec 9, 2008
  4. Helmut Jarausch
    Replies:
    4
    Views:
    6,536
    Ethan Furman
    Jul 15, 2009
  5. Matt Young
    Replies:
    4
    Views:
    399
    Garrett Fitzgerald
    Jan 31, 2004
Loading...

Share This Page