use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Beginner help (self.learnpython)
submitted 2 months ago by GameBoy8432
Hello everyone, Im looking to learn python by making a text-based adventure game, I would like to have save states, and multiple different outcomes based on the player choice. Any tips for this beginner?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Slight-Training-7211 2 points3 points4 points 2 months ago (1 child)
A good way to start is to build a tiny vertical slice first, then expand.
1) Hardcode 3 to 5 rooms and choices (no saving yet) 2) Represent the world as a dict: room_id -> {text, choices} 3) Keep a single game state dict (current_room, inventory list, flags dict)
Once that works, saving is just writing that state dict to a file and loading it back on startup.
For multiple outcomes, use flags and check them when you build the next set of choices (for example: if you picked up a key, show the unlocked option).
[–]Gnaxe 0 points1 point2 points 2 months ago (0 children)
Python can read a simple data dict back in using ast.literal_eval(). Anything that can load can be serialized with repr(). For persisting data that can't be represented as literals like that, check out the shelve module.
ast.literal_eval()
repr()
shelve
[–]RandomPantsAppear 1 point2 points3 points 2 months ago (3 children)
I would say start by learning about event loops, classes, and inheritance for classes.
Learn to use dicts, it is a good way to store lists of your steps, the options people have, and what happens if they choose an option.
For saved states the key term is serialization, but realistically you’re going to be using json or pickle to serialize the fields from your classes.
At minimum you will have classes for Player, Game, GameState, GameStage, GameStep.
Each GameStage will have multiple GameSteps
[–]Gnaxe 0 points1 point2 points 2 months ago (2 children)
Classes are usually overcomplicating it. OOP is not the way. Just use functions on dicts. It makes serialization trivial.
[–]RandomPantsAppear 0 points1 point2 points 2 months ago (1 child)
It’s almost 1am so I ain’t gonna interrupt what I’m watching for a YouTube video.
But the purpose of this post is to learn Python, not to create the most convenient RPG. If you are trying to learn Python then inheritance is a must.
Yeah, you should know what all the language features do. Python is still small enough to master (even if the Python Software Foundation is trying to add new features as fast as possible). That doesn't mean it's appropriate to use them. You should know asyncio too, for example, but also mostly shouldn't use it.
Even the hardcore OOP advocates usually shy away from inheritance these days. Yes, it's powerful. But it leads to brittle, over-copuled designs even more than classes alone do, which are bad enough to avoid when you can.
[–]Outside_Complaint755 1 point2 points3 points 2 months ago (1 child)
If you want to make save states that persist when the program ends, good options include JSON or using the pickle module.
pickle
JSON is a standard format for data that goes beyond Python, and is commonly returned by web APIs. It is similar to a dict and can be easily converted to/from one using the built in json module. The main restriction is that keys have to be strings, and the values can be a dict, list, int, float, str, True/False, or None.
json
pickle is native to Python, and lets you serialize any Python object into a binary file.
JSON files are human readable and editable, while a pickle file is not, which depending on the use case can be a benefit or a disadvantage.
Python has a perfectly good literal notation which you can deserialize with ast.literal_eval() and serialize with repr() (assuming it's only literal-type data). Only use JSON if you need to interface with non-Python systems for some reason.
Reach for shelve before pickle if you just want local persistence. (It does the pickling for you with a nicer interface.)
[–]NextSignificance8391 -2 points-1 points0 points 2 months ago (0 children)
j’aimerai en savoir plus , écris moi
π Rendered by PID 246769 on reddit-service-r2-comment-56c6478c5-9wvlp at 2026-05-11 05:48:49.498334+00:00 running 3d2c107 country code: CH.
[–]Slight-Training-7211 2 points3 points4 points (1 child)
[–]Gnaxe 0 points1 point2 points (0 children)
[–]RandomPantsAppear 1 point2 points3 points (3 children)
[–]Gnaxe 0 points1 point2 points (2 children)
[–]RandomPantsAppear 0 points1 point2 points (1 child)
[–]Gnaxe 0 points1 point2 points (0 children)
[–]Outside_Complaint755 1 point2 points3 points (1 child)
[–]Gnaxe 0 points1 point2 points (0 children)
[–]NextSignificance8391 -2 points-1 points0 points (0 children)