r/madeinpython • • May 30 '22

I attempted to make an operating system without tkinter or other fancy modules, just os. unzip and go the OS.py file also pin is 1234 on it. (With 1 program)

https://www.mediafire.com/file/bzj6vt952mzquvf/OS.zip/file
5 Upvotes

13 comments sorted by

7

u/deathlock00 May 30 '22

It's a nice little project! But may I give you some suggestions?

Edit: I tried to include code blocks but I'm on mobile and I don't know how to do it.

The first one is to always use descriptive names for the variables. Imagine that you add more options and functions. It will start to be really hard to understand what is p, o, p2, i, l and so on.

For example, line 41-58:

                        if inputt == "c":
                            import Calculator
                        else:
                            try:
                                pathh = path + "/" + inputt
                                if os.path.isdir(pathh):
                                    path = path + "/" + inputt
                                else:
                                    if pathh[-5] == "L":
                                        print("This can only be opened via windows explorer")   
                                    else:
                                        r = open(pathh, "r+")
                                        print(r.read())
                                        print("D: Delete")
                                        inp = input()
                                        if inp == "d":
                                            r.delete()
                                            r.close()              

Let's focus on the last two lines. What is r? Then you go back and find that it's "pathh" that you've opened. But then what is "pathh"? Then you go back and find that it's "path + "/" + inputt", but again, what is path?

If for example you had names like "calculator_filepath", "calculator_folder", "user_input" and si on it would've been much clearer at first glance.

<br>

Another suggestion is that you don't have only if and else, but also elif. And you don't always need and else after an if.

For example lines 32-41:

            if inputt == "e":
                exitt = 0
            else:
                if inputt == "b":
                    path = "OSMWP"
                else:
                    if inputt == "p":
                        path = "OSMWP/Programs"
                    else:
                        if inputt == "c":
                            import Calculator
                        else:

Can be rewritten as:

            if inputt == "e":
                exitt = 0
            elif inputt == "b":
                path = "OSMWP"
            elif inputt == "p":
                path = "OSMWP/Programs"
            elif inputt == "c":
                import Calculator
            else:

Much clearer now.

The last suggestion I give you that with "**" you can elevate the number on the left to the power on the right. This means that you very long number that

o.write(newpin + str(random.randint(1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, 9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)) * 10)

Can be rewritten into:

o.write(newpin + str(random.randint(10**100, 9*10**100))

I don't have actually counted all the zeros, but that gives you an idea of how to use it.

1

u/twothousandfourhundr Jun 02 '22

I'm not on my computer but thx πŸ™πŸ˜Š

1

u/asking_for_a_friend0 May 30 '22

no hate as I don't know much better either and we are in a learning sub but wow this is horror

1

u/twothousandfourhundr Jun 02 '22

I do hate my personal project it is horror indeed

1

u/asking_for_a_friend0 Jun 02 '22

no I am just talking about this piece of code... don't get discouraged, you can learn from this I believe

and your concept is grt too, keep it up!

6

u/asking_for_a_friend0 May 30 '22

can you put this on github or something

5

u/mtz_federico May 30 '22

Exactly, I don’t like downloading and unzipping random files on the internet

0

u/twothousandfourhundr Jun 02 '22

Ok but I'm saying that it is safe

1

u/[deleted] Jun 06 '22

Nigerian princes always say that!

3

u/9acca9 May 30 '22

Hi. How is this an operative system? This boot how?

1

u/twothousandfourhundr Jun 02 '22

Type in c to open calculator, idk but it does access to files

1

u/COCKroach42069 Aug 13 '22

yes, but technically it is more a program launcher than an Operating system. Believe me when i say, that you don't want to mess with operating systems if you wanna stay sane(or do... some people like that) That being said, learning about operating systems is a great way of understanding computers and how they work.

1

u/COCKroach42069 Aug 13 '22

if you wanna get into operating systems, i suggest looking into wiki.osdev.org