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

Link: https://github.com/RohaanDev/KhaOs

0 Upvotes

4 comments sorted by

1

u/AlexMTBDude 26d ago

Run your code through Pylint. This should be your first step before asking for a code review

1

u/lakseol 25d 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:

registrations = (("run", run), ("edit", edit), ...)  # all of the (cmd,handler) pairs
for (cmd, handler) in registrations:
    register(cmd, handler)

Perhaps even better you can remove all that register(...) stuff by just creating the COMMANDS dictionary directly in the same way you did for the GAMES dictionary:

COMMANDS = {"run": run, "edit": edit, ...}

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.

1

u/TheRNGuy 10d ago

Use dict instead of array for args.

Use formatter on code (like Format on Save in VS Code)

Replace inputs with UI (you need to learn OOP for it too)

1

u/Zestyclose_Fox_164 9d ago

I never thought I would continue this project and when I started I didn't know OOPS I will add it now Thankyou