问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/59914865/index-number-to-large-for-python