Skip to content

Commit

Permalink
Merge pull request #79 from cwalv/master
Browse files Browse the repository at this point in the history
fix exception when opening .dbf with zero records
  • Loading branch information
karimbahgat committed Feb 19, 2017
2 parents 49f15c5 + bc6c4a7 commit 616bf26
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions shapefile.py
Expand Up @@ -482,7 +482,7 @@ def __dbfHeader(self):

def __recordFmt(self):
"""Calculates the format and size of a .dbf record."""
if not self.numRecords:
if self.numRecords is None:
self.__dbfHeader()
fmt = ''.join(['%ds' % fieldinfo[2] for fieldinfo in self.fields])
fmtSize = calcsize(fmt)
Expand Down Expand Up @@ -548,7 +548,7 @@ def __record(self):
def record(self, i=0):
"""Returns a specific dbf record based on the supplied index."""
f = self.__getFileObj(self.dbf)
if not self.numRecords:
if self.numRecords is None:
self.__dbfHeader()
i = self.__restrictIndex(i)
recSize = self.__recStruct.size
Expand All @@ -558,7 +558,7 @@ def record(self, i=0):

def records(self):
"""Returns all records in a dbf file."""
if not self.numRecords:
if self.numRecords is None:
self.__dbfHeader()
records = []
f = self.__getFileObj(self.dbf)
Expand All @@ -572,7 +572,7 @@ def records(self):
def iterRecords(self):
"""Serves up records in a dbf file as an iterator.
Useful for large shapefiles or dbf files."""
if not self.numRecords:
if self.numRecords is None:
self.__dbfHeader()
f = self.__getFileObj(self.dbf)
f.seek(self.__dbfHeaderLength())
Expand Down

0 comments on commit 616bf26

Please sign in to comment.