AttributeError:'str'对象没有属性'toInteger' [英] AttributeError: 'str' object has no attribute 'toInteger'

查看:358
本文介绍了AttributeError:'str'对象没有属性'toInteger'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用python编写一个代码来在ArcMAP中生成一个点shapefile。我有1000个随机可能性(在FileA中),我需要尝试所有这些。 FileA是FileB位置的索引。

此外,对于每个生成的序列,我正在从3个点看Voronoi多边形区域的演变在每个序列中包含了50分,共计50分。

当我运行代码时,我有这个消息使我困惑:

  tempXYFile.writerow('{0},{1}'.format(coordinates [entry.toInteger()] [0],coordinates [entry.toInteger ()] [1]))
AttributeError:'str'对象没有属性'toInteger'

这是我的代码:

  

$创建1000个XY序列
print'开始脚本
sequences = csv.reader(open('FileA.csv','rb '),delimiter =',')
coordinates = []

#读取火山坐标并存入内存
print'开始读取坐标到内存'
coordinates_file = csv.reader(open('FileB.csv','rb'),delimiter =',')
坐标为[1:]:
coordinates.append(坐标)
del coordinates_file

## i = 1
序列中的序列:
## print'序列号{0}'格式(i)
j = 1
tempXYFile = csv.writer(打开('tempXY.csv','wb'),delimiter =',')#添加参数以创建文件(如果不存在)
用于依次输入:
tempXYFile.writerow('{0},{1}'.format(coordinates [entry.toInteger()] [0],coordinates [entry.toInteger()] [1]))
print格式(j,坐标[entry.toInteger()] [0],坐标[entry.toInteger()] [1])$ ​​b $ bj = j + 1
i = i + 1
del tempXYFile

print'脚本结束'


解决方案Python没有 toInteger()函数用于你想要的字符串改为用户 int(entry [])


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.

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'

I'll appreciate any help !

This is my code:

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 doesn't have a toInteger() function for strings you will want to user int(entry[]) instead.

这篇关于AttributeError:'str'对象没有属性'toInteger'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆