Python - ValueError:sign必须是值为0或1的整数

时间:2018-05-16 01:01:54

标签: python valueerror

with open("{}.json".format(ctx.message.author.id), "r") as json_file:
    profileData = json.load(json_file)
    data = profileData[ctx.message.author.id]

with open("attacks.json") as json_data:
    items = json.load(json_data)

thing = "soldier"
data[thing + "#"] = "{}".format(int(data[thing + "#"]) - int(soldier))
thing = "sniper"
data[thing + "#"] = "{}".format(int(data[thing + "#"]) - int(sniper))
thing = "demolitionist"
data[thing + "#"] = "{}".format(int(data[thing + "#"]) - int(demolit))
thing = "spy"
data[thing + "#"] = "{}".format(int(data[thing + "#"]) - int(spy))
thing = "armored_vehicle"
data[thing + "#"] = "{}".format(int(data[thing + "#"]) - int(armored_vehicle))
thing = "tank"
data[thing + "#"] = "{}".format(int(data[thing + "#"]) - int(tank))

random_percent_j = ["1.1", "1.25", "1.4"]
data["balance"] = "{}".format(int(data["balance"]) + int(items["1"]["deploy_cost"]) * int(soldier) * random.choice(Decimal(random_percent_j)))

这是我得到的,我以前从未见过这种类型的错误。其中一些是JSON,所以这里是代码:https://hastebin.com/hoseyikove.json

  File "run.py", line 220, in attack
data["balance"] = "{}".format(int(data["balance"]) + int(items["1"]["deploy_cost"]) * int(soldier) * random.choice(Decimal(random_percent_j)))
ValueError: sign must be an integer with the value 0 or 1

1 个答案:

答案 0 :(得分:3)

您在最后一行代码中实例化了一个带有列表(Decimal)的random_percent_j对象。它应该是:

Decimal(random.choice(random_percent_j))

random.choice(Decimal(random_percent_j))