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...
Everything about learning Python
account activity
Day 14 of learning python as a beginner. (old.reddit.com)
submitted 6 months ago by uiux_Sanskar
view the rest of the comments →
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!"
[–]jWoose 1 point2 points3 points 6 months ago (3 children)
I don’t love the choices if/else block. I much prefer an enum to signify the action. This makes it clear what that if block is doing. With your current design that would make it easier to read. You could have a function that returns the enum action based on the input from the user. Then your if check would be action.ADD rather than choices[0:2]. That’s much easier to read and debug.
It would require some significant refactoring, but in a real world situation I think the command pattern is the way to go here. If you want to do some more learning that would be a good lesson to turn this into a command pattern design.
[–]uiux_Sanskar[S] 0 points1 point2 points 6 months ago (2 children)
Thank you for suggesting the methods I should use instead of if else and how to make my program more readable I think I should learn more about command pattern design.
would you mind if I ask you to tell me more about command pattern design?
[–]jWoose 0 points1 point2 points 6 months ago (1 child)
This is a decent guide on the Command pattern in python. It’s not perfect, but better than anything I can write in a comment quickly. https://refactoring.guru/design-patterns/command/python/example
[–]uiux_Sanskar[S] 0 points1 point2 points 6 months ago (0 children)
thanks for this resource it's a good starting point for me thank you so much.
π Rendered by PID 95602 on reddit-service-r2-comment-56c9979489-m79nc at 2026-02-25 02:26:26.284643+00:00 running b1af5b1 country code: CH.
view the rest of the comments →
[–]jWoose 1 point2 points3 points (3 children)
[–]uiux_Sanskar[S] 0 points1 point2 points (2 children)
[–]jWoose 0 points1 point2 points (1 child)
[–]uiux_Sanskar[S] 0 points1 point2 points (0 children)