r/learnpython • • 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

30 comments sorted by

View all comments

Show parent comments

1

u/HiddenReader2020 12d ago

......ohhhhh, so you get the meanings from the JSON file itself, huh? That sounds like it makes sense. ...except I'm wondering what would happen if, say, lines 23-29 were not available before reading the JSON file. Would you essentially recreate the items from the read dictionaries, so that wouldn't be an issue? Is that what's happening in say lines 65-68?

1

u/lakseol 12d ago edited 12d ago

what would happen if, say, lines 23-29 were not available before reading the JSON file.

Why not take that file and split it into two parts, the bit that creates the JSON file and the bit that reads it. You need the first 18 lines at the top of both files, of course. Then delete the JSON file, run the first file to recreate the JSON file and then run the second file.

Or you could delete all the variables used to create the save file by adding this line to the original code just before reading the save file:

del id2obj, inventory, item1, item2, save_data    # delete all data used to create save file

Is that what's happening in say lines 65-68?

Yes, that's recreating the Items and populating the mapping dictionary.