当我试图访问对象“e”的任何方法时,就会出现错误“AttributeError:instance has no attribute”。我假设当我创建对象时,我没有以正确的方式进行。有人知道为什么吗?在
import shapefile
sf = shapefile.Reader('C:/users/name/desktop/shapefiles/Polygon')
e = shapefile.Editor(shapefile = 'desktop/shapefiles/Polygon.shp')
indexesMpart = [i for i, shape in enumerate(shapes) if len(shape.parts) > 1]
for index in indexesMpart:
e.field('something', fieldType = 'C', size = '4')
在评估错误和代码后形状文件.py,编辑器对象返回ValueError的原因是由于.dbf文件中与.shp文件关联的属性为空。对于my.shp文件中的每个项,一个简单的属性[0,1,2,3,4,5],就可以满足试图调用records方法的构造函数的要求。在
谢谢你的帮助,塞拉斯,如果没有你的指导,是不可能解决这个问题的。在
看一下这个模块的代码,我能看到的唯一方法(实际上是a patch submitted)可以得到一个没有
fields
属性的Editor
对象,如果第1043行的条件if os.path.isfile("%s.shp" % base):
因找不到.shp
文件而失败。你确定你的文件存在并且你用正确的路径和文件名初始化吗?在相关问题 更多 >
编程相关推荐