A Digital Garden - frequent growth but a bit weedy in the back corner
Maybe I’m missing something here but Python’s system for creating, importing, publishing, and installing modules and packages and distributables seems… complicated. And a bit arbitrary. And more than a little counter-intuitive. And distinctly voodoo. Of course, it may well be that it only seems complicated to me because I haven’t got a clue what I’m doing. Or, perhaps it’s wonderfully elegant and efficient and powerful and I just don’t appreciate those features of it yet because I haven’t got a clue what I’m doing. Or, maybe I’m just a bit of a noob who hasn’t got a clue what he’s doing. Given that there appears to be a common element associated with my lack of clue, it’s time to have an explore. Experiment time!
A few things have appeared on my radar during my flounderings so I’ve compiled a list of things to dig into:
Given the complexity of the whole thing and the number of rabbit holes that have distracted me from my well intentioned learning path to the point that I’ve forgotten, on several occasions, what exactly I’ve been trying to achieve, I think I need to take a methodical approach. With that in mind, I’m going to start with the very basics.
Caveat: some of what I’m going to try here is stupid, poor practice, obviously going to fail etc. etc. I’m working on the principle that you need to understand what things don’t work in order to understand why the things that do work, work. For example, putting my ‘utility’ code in a file called utils.py (as I’m about to do) will turn out to be a bad idea because there’s already a package in PyPi with that name. Don’t get me started on why that little wrinkle is already starting to piss me off.
I’m starting with everything in a single folder experiment0:
utils_experiments/
└── experiment0
├── project.py
└── utils.py
The ‘utility’ code lives in utils.py:
def a():
print("a")and it gets exercised by code in project.py
import utils
utils.a()As expected that works just fine:
experiment0/ with python3 project.py it prints out a.utils_experiments/ with python3 experiment0/project.py it also prints out a.