Error when accessing replit database in python
Whenever i try to access my database with value = db["key"]
I get the error TypeError: unexpected type "float"
.
This never happened before, can someone tell me what this means?
the file with problems = cogs/xp.py
Voters
your repl is private so we can't see your code.
@Coder100 thx for letting me know, i set it to public
i see, what are you exactly trying to do here?
@ZoutigeWolf
the types are already correct, and no type will ever need to be converted. Also, these values don't appear to be valid dict values.
@Coder100 same error happens when i don't do the
dict()
it was just a test i forgot to removewhat line? @ZoutigeWolf
@Coder100 any line where i want to get a value from the database
example:
xpDB = db["xp"]
well i mean you put the dict function on all of them so you should remove that @ZoutigeWolf
@Coder100 I did and it still errors
@ZoutigeWolf

no you haven't?
@Coder100 for me it shows

multiDB = db["xpMulti"]
strange maybe the file didn't save @ZoutigeWolf
@Coder100 I found the solution, apparently a dict in the database can't have a float as a value.
The xp is normally an int but the multiplier made it a float so i now round that to an int.
And I now store the multipliers as a string which i can later convert back to a float
@ZoutigeWolf Replit DB is based on JSON and it doesn't support anything other than strings as keys.
@xfinnbar ohhhhhhh that makes a lot of things clear.
but when i stored info on my own pc in JSON for a project I was able to store integers and floats
@ZoutigeWolf They were converted to strings tho.
no that's ridiculous json can have numbers as the key
however, dicts cannot. @xfinnbar
nice solution
yeah I thought the python db would get all these nitty types down for you, but I guess not @ZoutigeWolf
@xfinnbar i had keys as strings and values as floats / ints in my json, they werent converted
in json, floats and ints are indistinguishable and everything is a float
@ZoutigeWolf