GeospatialPython / pyshp

This library reads and writes ESRI Shapefiles in pure Python.
MIT License
1.1k stars 260 forks source link

TypeError: object of type 'Reader' has no `len()` #133

Closed Daniel-M closed 6 years ago

Daniel-M commented 6 years ago

Hey everyone. I'm running pyshp 1.2.12 (downloaded today from PyPI) within Python 3.6.4 (and IPython 6.2.1.). Applying len() to a shapefile trows a TypeError as in the example below,

import shapefile

sf  = shapefile.Reader("shp/shpfile.shp")
print(len(sf))
TypeError: object of type 'Reader' has no len()

Also tried loading the shapefile as a Python file descriptor as,

import shapefile

shpfile = open("shp/shpfile.shp","rb")
sf  = shapefile.Reader(shp=shpfile)
print(len(sf))
TypeError: object of type 'Reader' has no len()

Did I do something wrong?

Daniel-M commented 6 years ago

It seems that the method __len__(shapefile.Reader) wasn't implemented in version 1.2.12 (the one on PyPI). Cloned this repository and the the master branch allowed me to use len(sf)