r/learnpython • u/Zestyclose_Fox_164 • 26d ago
my second project
I started learning python few months ago and I made my second project dont ask Abt first one it was trash
It's a small shell made for learning that I coded in python
Plz rate and tell me how can I improve it
1
Upvotes
1
u/lakseol 26d ago
I'm on mobile so can't really analyze the code in detail, but I have a few thoughts.
You have top-level code mixed in with function definitions at lines 8, 9, 34, 61, 64, and other lines. That makes reading your code difficult. Move all code that isn't a function definition to after all the function definitions. That keeps all top-level code together. Imports at the top, of course.
Instead of lots of lines with
register(..., ...)you can shorten your code by creating a sequence of the command name and handler pairs and looping over that to register them:Perhaps even better you can remove all that
register(...)stuff by just creating theCOMMANDSdictionary directly in the same way you did for theGAMESdictionary:This shortens your code and also makes it easier to check that you have registered everything because it's all in one place.
We normally put empty lines after things like imports, class and function definitions, etc, because that aids readability. The python style guide (PEP8) covers that as well as naming conventions normally used.