python 的索引号过大

index number to large for python

大家好,我正在尝试使用从 API 类型中提取的一些数据来制作一个简单的 json。我希望 "key" 成为 ID 之一,但是我收到以下错误 "cannot fit 'int' into an index-sized integer"。所以环顾四周,我认为这意味着我尝试关联的数字作为密钥大于数字可以是多少?所以我在考虑一些可能的解决方法,并且想知道是否有人知道解决这个问题的方法。我能想到的最好的事情是创建一个字典,其中包含指向该数字的唯一键。请发现下面的代码应该准备好 运行 原样。

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 的处理方式因平台而异 - 请参阅: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)。如果我是对的,你必须改变你的方法。也许使用字典而不是列表。或者只是通过串联的方式构建您的 CSV 字符串。有很多可能的方法。您的代码可能适用于较小的数字。