0
我目前正在使用python(在Ubuntu上)的Visual trace路径程序。我正在使用pygeoip来获取坐标(以及其他信息)。我将每个IP的数据存储在一个列表(listcoor)中。我遇到的问题是访问一个特定的字典项一旦它被放置在listcoor访问列表中的字典中的项目
def vargeolocating(matchob): # matchob is a list of IPs
print "Geolocating IP addresses"
gi = GeoIP.open("/usr/share/GeoIP/GeoLiteCity.dat",GeoIP.GEOIP_STANDARD)
i = 0
listcoor = []
while (i < len(matchob)):
holder = gi.record_by_addr(matchob[i])
if holder is None:# for local addresses
print "None"
else:
listcoor.append(holder)
i = i + 1
print holder['longitude'] # Prints out the last longitude
print listcoor[12] # Prints all information about the last IP (this longitude matchs the above longitude
print listcoor[12['longitude']] # Should print just the longitude, matching the two longitudes above
最后打印显示错误“类型错误:‘诠释’对象有没有属性‘的GetItem’”
另外,你的循环可以简化为:'holder_iter =(GI。 record_by_addr(m)for m in matchob);如果'gi.record_by_addr'获得一个对象或None,'listcoor = filter(None,(gi.record_by_addr(m)for m in matchob)''listcoor = [持有者持有者持有者持有者。 – hughdbrown 2013-03-14 13:54:53