add fields in a existing dbf

Ethan Furman ethan at
Tue Aug 11 18:12:44 CEST 2009

Alonso Luján Torres Taño wrote:
> Hi!
> I'm trying to modify a dbf adding a new field in a python script, but I 
> can't.
> Just I can add a field in new dbf created in the same script.
> I tryed with:
>     db = dbf.Dbf("../filesource.dbf",new =False, readOnly=False)
>     ...
>     db.addField(("PESO","N",32,8))
> and return error:
>     Traceback (most recent call last):
>       File "", line 34, in <module>
>         db.addField(("PESO","N",32,8))
>       File "/usr/lib/python2.5/site-packages/dbfpy/", line 229, in
>     addField
>         "structure can't be changed")
>     TypeError: ('At least one record was added, ', "structure can't be
>     changed")
> I have not idea of what error I make.
> If someone can help me, I'll so gratefull.
> Thanks!

I am not familiar with dbfpy, but the dbf files I am familiar with do 
not support 32 digit Numerics.  Did you mean 12?

At any rate, if you use

the commands would be:

import dbf
db = dbf.Table("../filesource.dbf")
db.add_fields("peso N(12.8)")

and you'll have your field -- assuming, of course, you have write 
priveleges, etc.

Hope this helps!


Disclaimer:  I am the author of python-dbase.

More information about the Python-list mailing list