r/learnpython • • Nov 05 '20

How does one learn to make well-structured programs? Mine are dumpster-fires.

So I just (kind-of) finished reading Automate The Boring Stuff With Python, and for the past month I've felt like a big-brained super-hero automating myself out of a job (Data Analyst).

The problem is, I feel I missing something along the way. I don't understand the proper way to use functions, what a class is, why people have multiple files in a program, how/why people use GitHub...probably some other things I haven't discovered yet.

They all seem to be related to organization? Is there a "How To Structure Your Python Stuff With Python" book?

478 Upvotes

98 comments sorted by

View all comments

1

u/m4rx Nov 05 '20

It's mostly something that comes with time and practice. Understanding Classes / Imports / Inheritance is huge, I'd suggest reading up on creating classes as a start.

I am an experienced programmer that has moved to Python for a new position and my projects* quickly become dumpster fires as well, but the more you write the cleaner your code becomes.

*I hacked together imports so I can import the app->db to other classes, I hate the __init__.py method and would prefer to keep everything in `app.py` / `routes.py` etc. but kept getting cyclical import errors stopping the code.

I understand I should look into using Flask Blueprints but couldn't find any examples online and didn't have time during a hackaton to learn it. I found a project using __init__.py like I wanted and just copied that :X