David Lyon írta:
Hi,

Try not opening the file in append mode (no "a+")

Inside the logic, there is already a seek to the end of the file
and the record counters at the start of the file need updating
too.
The first thing I tried is to use a filename instead of the file object but it didn't work. Then I just tried "r+b" and it worked fine. Thank you!

BTW here is ist constructor:

   def __init__(self, f, readOnly=False, new=False, ignoreErrors=False):
       """Initialize instance.

       Arguments:
           f:
               Filename or file-like object.
           new:
               True if new data table must be created. Assume
               data table exists if this argument is False.
           readOnly:
               if ``f`` argument is a string file will
               be opend in read-only mode; in other cases
               this argument is ignored. This argument is ignored
               even if ``new`` argument is True.
           headerObj:
               `header.DbfHeader` instance or None. If this argument
               is None, new empty header will be used with the
               all fields set by default.
           ignoreErrors:
               if set, failing field value conversion will return
               ``INVALID_VALUE`` instead of raising conversion error.

       """
       if isinstance(f, basestring):
           # a filename
           self.name = f
           if new:
               # new table (table file must be
               # created or opened and truncated)
               self.stream = file(f, "w+b")
           else:
               # tabe file must exist
               self.stream = file(f, ("r+b", "rb")[bool(readOnly)])
       else:
           # a stream
           self.name = getattr(f, "name", "")
           self.stream = f


I have never seen such a construct before. Index a tuple with a boolean???

               self.stream = file(f, ("r+b", "rb")[bool(readOnly)])
Best,

  Laszlo

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to