AttributeError: 'str' 对象没有属性 'toInteger' [英] AttributeError: 'str' object has no attribute 'toInteger'
问题描述
我正在使用 python 编写代码以在 ArcMAP 中生成点 shapefile.我有 1000 个随机可能性(在 FileA 中),我需要尝试所有这些.FileA是FileB所在位置的索引.
I'm writing a code using python to generate a point shapefile within ArcMAP. I have a 1000 random possibilities (in FileA), and I need to try all of them. The FileA is the index of the position of FileB.
此外,对于生成的每个序列,我正在查看 Voronoi 多边形的面积从 3 个点到 50 个点的每个序列(总共包含 50 个点)的演变.
In addition, for each sequence generated I'm looking at the evolution of the area of the Voronoi polygon from 3 points to 50 points in each sequence that contains a total of 50 points.
当我运行代码时,我收到一条令我困惑的消息:
When I run the code, I have this message which confuse me:
tempXYFile.writerow('{0},{1}'.format(coordinates[entry.toInteger()][0],coordinates[entry.toInteger()][1]))
AttributeError: 'str' object has no attribute 'toInteger'
我将不胜感激!
这是我的代码:
import csv
# create 1000 XY sequences
print 'Start of the script'
sequences = csv.reader(open('FileA.csv','rb'),delimiter=',')
coordinates = []
# read coordinates of volcanos and store in memory
print 'Start reading in the coordinates into the memory'
coordinates_file = csv.reader(open('FileB.csv','rb'),delimiter=',')
for coordinate in coordinates[1:]:
coordinates.append(coordinate)
del coordinates_file
##i = 1
for sequence in sequences:
## print 'sequence # {0}'.format(i)
j = 1
tempXYFile = csv.writer(open('tempXY.csv','wb'),delimiter=',') #add the parameter to create a file if does not exist
for entry in sequence:
tempXYFile.writerow('{0},{1}'.format(coordinates[entry.toInteger()][0],coordinates[entry.toInteger()][1]))
print 'Entry # {0}: {1},{2}'.format(j, coordinates[entry.toInteger()][0],coordinates[entry.toInteger()][1])
j = j + 1
i = i + 1
del tempXYFile
print 'End of Script'
推荐答案
Python 没有 toInteger()
函数来处理你想要使用的字符串 int(entry[])
代替.
Python doesn't have a toInteger()
function for strings you will want to user int(entry[])
instead.
这篇关于AttributeError: 'str' 对象没有属性 'toInteger'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!