Hello im coding a program for hypixel skyblock minecraft that tells me a price of items that can be sold for a higher price, the program is done but im running into a issue. I have made a config.json file and it contains information like discord webhook lowest price and to notify the user if a item is found. Im having problems with the lowest price function, basically when i put into the config lowest price and i put the value to 1 the program doesnt work and gets a traceback. The traceback doesn’t matter because i know the issue. When i put the number into config it doesnt work but when i set lowestprice = 1 in program manually it works like when i put the number into config the program thinks maybe the number is a text or something. heres the config code
with open("config.json", "r") as f:
data = json.load(f)
webhookread = data["webhook"]
notifyread = data["notify"]
lowestpriceread = data["lowestbin"]
WEBHOOK = webhookread
LOWEST_PRICE = lowestpriceread - THE ISSUE
NOTIFY = notifyread
is there a way i could make the config file put the number as a real number not a text or any of that? so i can still use the config for numbers?
==========================
Thank you for helping me! it works now
>Solution :
Are the numbers in the json file stored as strings or as numbers? if the json looks like this:
{
"lowestbin" : "123.45"
}
then the price is saved as string and will need to cast to a float type. This is simple to do:
lowestpriceread = float(data["lowestbin"])
Note: this code will thrown an exception if the data in the json cannot be converted into a float.