尝试访问编辑器方法时出错

2024-03-29 05:22:56 发布

您现在位置:Python中文网/ 问答频道 /正文

当我试图访问对象“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')

Tags: 对象方法instancenoinfor错误attributeerror
2条回答
Traceback (most recent call last):
  File "C:\Users\something\Desktop\test2\testing.py", line 5, in <module>
    e = shapefile.Editor(shapefile = 'C:/Users/something/Desktop/test2/testing')
  File "C:\Python27\lib\site-packages\pyshp-1.2.0-py2.7.egg\shapefile.py", line 1048, in __init__
    self.records = r.records()
  File "C:\Python27\lib\site-packages\pyshp-1.2.0-py2.7.egg\shapefile.py", line 525, in records
    r = self.__record()
  File "C:\Python27\lib\site-packages\pyshp-1.2.0-py2.7.egg\shapefile.py", line 490, in __record
    value = int(value)
ValueError: invalid literal for int() with base 10: '**********'

在评估错误和代码后形状文件.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文件而失败。你确定你的文件存在并且你用正确的路径和文件名初始化吗?在

相关问题 更多 >