python的索引号较大 [英] index number to large for python
问题描述
您好,我正在尝试使用从某种类型的API中提取的一些数据来制作一个简单的json.我希望键"是ID之一,但是出现以下错误无法将'int'装入索引大小的整数".因此,环顾四周,我认为这意味着我要关联的数字大于键可以大于的数字?因此,我正在考虑一些可能的解决方法,并想知道是否有人知道解决此问题的方法.我能想到的最好的事情是创建一个具有唯一键的字典,该键指向该数字.请找到下面的代码,即可按原样运行.
Hello all I am trying to make an easy json with some data i pull from a type of API. I want the "key" to be one of the ids, however i get the following error "cannot fit 'int' into an index-sized integer". So looking around I think this means that the number I am trying to associate as the key is larger than a number can be?? So I was thinking about some possible work-arounds for this and was wondering if anyone knows a way to get around this. The best thing I can think of is create a dictionary with unique keys that point to that number. Please find the code below should be ready to run as is.
import json
import requests
import csv
response = requests.get("https://esi.evetech.net/latest/markets/10000002/orders/?datasource=tranquility&order_type=all&page=1&type_id=34")
data = []
data.append({"duration","is_buy_order","issued","location_id","min_vloume","order_id","price","range","system_id","type_id","volume_remain","volume_total"})
with open("D:\\Code\\EveFinance\\orders.json","w") as jsonFile:
for index in response.json():
#print(index['order_id'])
id = index['order_id']
print(id)
data[id]
# data[id].append({
# 'duration':index['duration'],
# 'issued':index['issued'],
# 'location_id':index['location_id'],
# 'min_vloume':index['min_vloume'],
# 'price':index['price'],
# 'range':index['range'],
# 'system_id':index['system_id'],
# 'type_id':index['type_id'],
# 'volume_remain':index['volume_remain'],
# 'volume_total':index['volume_total']
# })
print(data)
#file = open("D:\\Code\\EveFinance\\orders.json","w")
#jsonString = json.dumps(data)
#file.write(jsonString)
ERROR:
[Running] python -u "d:\Code\EveFinance\dataSort.py"
5586835679
Traceback (most recent call last):
File "d:\Code\EveFinance\dataSort.py", line 14, in <module>
data[id]
IndexError: cannot fit 'int' into an index-sized integer
[Done] exited with code=1 in 0.949 seconds
推荐答案
啊.我正在Linux上测试您的代码,并且根据平台对 int
的处理方式有所不同-请参见:源).如果我是对的,那么您就必须改变自己的方法.也许使用字典而不是列表.或者只是通过串联方式构建CSV字符串.有很多可能的方法.可能您的代码可以使用较小的数字.
Ah. I was testing your code on Linux and it looks like int
is handled differently based on the platform - see: python handles long ints differently on Windows and Unix. On my setup sys.maxsize
returns: 9223372036854775807. On yours (Windows) I suspect it is 536870912 (source). If I'm right you have to change your approach. Maybe use a dictionary instead of a list. Or just build your CSV strings by way of concatenation. There are many possible ways. Probably your code would work with smaller numbers.
这篇关于python的索引号较大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!