I'm getting started with Python (it's high time I give it a shot), and I'm looking for some best practices.
My first project is a queue which runs command-line experiments in multiple threads. I'm starting to get a very long main.py
file, and I'd like to break it up. In general, I'm looking for: How do python programmers organize multiple source files? Is there a particular structure that works for you?
My specific questions include:
I can probably draw some of my own conclusions here by trial and error, but I'd rather start from something good.
The article Eric pointed to is awesome because it covers details of organising large Python code bases.
If you've landed here from Google and are trying to find out how to split one large source file into multiple, more manageable, files I'll summarise the process briefly.
Assume you currently have everything in a file called main.py
:
utils.py
for this example)main.py
into utils.py
main.py
add a single line at the top: import utils
Conceptually what this does is to create a new module called utils
in another source file. You can then import it wherever it's needed.