Ask coding questions

← Back to all posts
I'm trying to make this code work but I can't figure it out
MisledWater79 (0)

Me and my teacher tried to figure it out but we don't understand why it doesn't work.
When you put in a username in that is already taken it will just add it to the json file again.

Comments
hotnewtop
InvisibleOne (2675)

Well first off, you some some issues with your file system, JSON converts python dictionaries to a string so you can put them in a text file, although I've never tried it with actual .json files I don't see why it wouldn't work. I think the issue is on line 7, where you tell it to jsonify f, when it should be to jsonify the value of f, try changing that line to users = json.load(f.read()) and let me know if it works.

MisledWater79 (0)

@InvisibleOne It didn't work. I think its the if statement in line 9 that doesn't work but idk. The reson your didn't work is the "r" in open("database.json","r") is telling it to read the file.

InvisibleOne (2675)

Well I usually don't do it with a json file, this is the way I would do it: https://replit.com/@InvisibleOne/Economy#main.py

MisledWater79 (0)

@InvisibleOne I don’t know if you can but could I use a .env?

InvisibleOne (2675)

You could, but the issue is that you cannot write to an env, at least I haven't figured out a way to do it on replit.

novaflippers (48)

"e" shouldnt be the name. It should be the name of the JSON directory.

MisledWater79 (0)

@novaflippers Yeah I am just messing with it right now but 'e' is suppose to be just username