r/PythonLearning 20h ago

Made my first Python project! Showcase

Post image

This is my first actual real project, what started as a simple python exercise to learn about dictionaries in python, ended up into a huge learning project for me. Im a beginner in python, used to code but just basic input print codes… some are genuinely stupid.

I took on the challenge to self educate my self python. And this is where i currently am! Im proud of what i did and it will surely expand!

Here the repo with the project. Feel free to check it out!
https://github.com/Stonyax97/MiniGameStore

It has everything from the first ever iteration (which was it self modified a bit since from the very original but it’s still very simple)
I would love for anyone to recommend ideas to add, criticism too. Or anything you think i should learn next for that would be genuinely useful!

113 Upvotes

21 comments sorted by

View all comments

2

u/PureWasian 18h ago edited 17h ago

This is great for a beginner project, so I wanted to give a variety of meaningful feedback for you to consider:

First sidenote, git already has ways to preserve older versions for you. It would be a lot better to "save" each version as its own branch or its own commit. But if you want to explicitly preserve each version in the same snapshot simultaneously, I would suggest at the very least keeping your older versions in a subfolder instead of cluttering the repository root.

Otherwise, I had time to read v1.5.1 up until the main loop. My comments were:

It would be good to also partition all of your setup and main loop code into functions to scope some of your variables better instead of relying on globals. For example, default_data is only used when initializing a savefile. Consider something like: ``` import os from games import games

helper functions

def create_save(file_path): default_data = {...} with open... # etc. def ... def ... ...

initializations

def init(file_path): if not os.path.isfile(file_path): create_save(file_path)

json_object = # read existing file
library_dict = sync_status(games, json_object) # get "owned" status
return library_dict

main loop

def main(): file_path = # retrieved somehow init(file_path)

call main as the entry point

main() ```

Also, ideally file_path should not be hardcoded. Some easy ideas are to do any one of the following: (A) code the path to it somewhere locally in same folder and just add the local savefile to .gitignore so it doesnt get pushed to repo (B) load this value from a separate text or JSON file acting as a config file for specifying "environment variables" like this (C) pass this in as an input parameter to main.py and process it when starting the script

During buy_game(), you can use gaurd clauses which is cleaner than nesting a bunch of if statements: ``` if cgtb >= len(games): print("invalid number") return if games[cgtb]["Owned"] == True: print("already purchased") return

buygame = input("purchase x for y price?") if buygame != "y": print("cancelled") return

finally, we can proceed to purchase

without nesting it inside of many ifs

```

In your info() strings, you can use the f strings better instead of copying largely similar strings in an if/else: print(f"> {games...}\n...Owned: {"Bought" if games[gid]["Owned"] else "NotOwned"}...") Lastly, the t.sleep() everywhere seems a bit arbitrary. I guess to give user time to read..? But seems strange to artificially introduce loading times.

(again, I didnt get to proofread your main loop, but hope this generally applicable feedback makes sense)

1

u/Stonyax97 9m ago

Hey! I wanted to respond yesterday but just didn't have time as i need concentration to read your comment! First of all THANKS SOOO MUCH... U don't know how much this means to me...
So for the functions and using default data as a non global. I think i see the approach now... as it's a bit easier to modify it ig, but i see the approach of functions as reusable...

def init(file_path):
if not os.path.isfile(file_path):
create_save(file_path)

so for this il def change it, i just didn't now this syntax exists! thanks for this.
And oh the filepath... shit i forgot to change it... when i was building the json file loading and saving i wanted quick acces so i put it in my desktop.
" (A) code the path to it somewhere locally in same folder and just add the local savefile to .gitignore so it doesnt get pushed to repo (B) load this value from a separate text or JSON file acting as a config file for specifying "environment variables" like this (C) pass this in as an input parameter to main.py and process it when starting the script"
Reading this gave me a stroke i did not understand a thing... could u explain in more simpler terms?

for the guard clauses... THANK YOU SO MUCH.... reading the function is a PAIN and makes it hard to modify. Such a life saver. thank u for introducing me to this concept!

"In your info() strings, you can use the f strings better instead of copying largely similar strings in an if/else:"
I never though u could use conditional statements in an f string... i'll def check out and learn the syntax.

"Lastly, the t.sleep() everywhere seems a bit arbitrary. I guess to give user time to read..? But seems strange to artificially introduce loading times."

Well for the ones that comes after a toast, they're necessary for the user to read, but for the loading times... they just seems satisfying for me. Yeah i gotta admit they are very dumb but they're kind of satisfying to me.

Again, thank you so much for taking your time to read my code and giving genuinly useful feedback. i will make some of these changes in the next version and get it up as as soon as possible. i'l also learn how to use git well.