我正在使用python编写代码以在ArcMAP中生成点shapefile。我有1000个随机可能性(在FileA中),我需要尝试所有这些。 FileA是FileB位置的索引。
此外,对于生成的每个序列,我正在观察Voronoi多边形区域从3个点到50个点的演变,每个序列包含总共50个点。
当我运行代码时,我收到的消息令我感到困惑:
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'
答案 0 :(得分:2)
标准Python中的字符串没有toInteger()
方法。错误消息非常清楚。如果您想将"37"
之类的字符串转换为整数37,请尝试使用int(entry)
。
为什么在代码中写toInteger()
?
答案 1 :(得分:2)
Python对于您希望用户toInteger()
的字符串没有int(entry[])
函数。
答案 2 :(得分:1)
对字符串不存在toInteger方法 检查一下:http://docs.python.org/library/stdtypes.html#string-methods
正确的形式是:
coordinates[int(entry)][0]