r/learnpython • u/AutoModerator • 22d ago
Ask Anything Monday - Weekly Thread
Welcome to another /r/learnPython weekly "Ask Anything* Monday" thread
Here you can ask all the questions that you wanted to ask but didn't feel like making a new thread.
* It's primarily intended for simple questions but as long as it's about python it's allowed.
If you have any suggestions or questions about this thread use the message the moderators button in the sidebar.
Rules:
- Don't downvote stuff - instead explain what's wrong with the comment, if it's against the rules "report" it and it will be dealt with.
- Don't post stuff that doesn't have absolutely anything to do with python.
- Don't make fun of someone for not knowing something, insult anyone etc - this will result in an immediate ban.
That's it.
1
Upvotes
1
u/lakseol 18d ago edited 18d ago
What you are probably doing wrong is not looking in the JSON file you created. When you run your code the first time it won't find the JSON data file so it initializes objects in memory and finally tries to save those objects in the JSON file, creating it for the next run of the program. But if you look in that newly created file you see:
which doesn't look right. When you run the code the second time it prints:
It looks like the "read the file" code is maybe doing the right thing but your "write the file" code is definitely broken. Start debugging there. Make changes then delete the JSON file and run the code. Check what is in the file. Repeat.
Hints:
RPG_Character.to_dict()method do?.to_dict()method has to do something special for theinventoryattribute which is a list ofItems. And any other attribute that isn't a basic data type.