Posts categorized under: python

"Building a basic package pt. 1: Bare Bones"

Every once in a while I get the itch to turn some one off script I wrote into a proper package. Turns out advice on the subject is a little scattered, and if you're anything like me it can be frustrating to track down relevant posts on the entire subject. So, just for fun, let's walk through the process of taking a one-off script I wrote and making it into a nice python package, complete with isolated testing, uploading to pypi, and convenient installation.

Now knowing my blogging habits, I'm splitting this into a few small posts in the hopes that I actually get through them. So lets take a current project I have and decide where to start.

"There is no such thing as magic"

Do you know my favorite fact about programming? In the end, everything is build from code and you can understand it all -- there is absolutely no magic. With enough effort, almost everything you interact with can be dug into, demystified, and explained. I know I often interact with various tools I use as if they were black boxes, either for lack of time, lack of interest, or a fear that I wouldn't understand them if I tried. But let's fight back against that.

So for this post, let's understand what's going on with python's virtualenv package.

"Hiding complexity with Context Managers"

Very reliably, my favorite part of programming is the simple process of taking a series of steps that I used to have to do by hand and packaging it up in a nice, reusable form. It's pretty wonderful that it remains just as rewarding now as it did when I wrote my first function in C++ 8 years ago.

So in that spirit, I figured I'd write down a few thoughts on python's context managers -- the latest built-in feature that I've grown quite attached to.

"Why namedtuples?"

If you had asked me to explain all I knew about Python's namedtuple class at the start of this year, I would have probably muttered something about mutability and trailed off into an uncomfortable silence. The fact of the matter was, I had seen them used once or twice but never really understood the reason they were used. Hopefully by the end of this entry I can explain at least a couple of places you might consider using them over the typical Python class.