Everything I know about Python...

Learn to Write Pythonic Code!

Check out the book Writing Idiomatic Python!

Discuss Posts With Other Readers at discourse.jeffknupp.com!

Should Engineering Managers Code?

Note: This post also appears on the blog of my employer, Enigma (enigma.io)

Earlier this year I made a career change: I decided to stop being an Individual Contributor (or "IC", i.e. someone who codes) and became the Engineering Manager of the team I was a member of. I call it a "career change" because it's important to recognize the move for what it is. All too often, such a change is viewed as the logical progression of an engineer's career. That's a shame.

It's a shame because being an engineer trains you to be a people manager about as well as it trains you to be a circus juggler. There are almost no transferable skills, save the domain knowledge you've acquired that will ostensibly help in managing projects. But (as every engineer will tell you), being a great engineer does not mean you'll be even a passable manager. Some companies (like my own) realize this and create parallel career paths for engineers that want to write code forever without mortgaging their advancement opportunities. Sadly, most companies are not so forward thinking.

Read on →


Python with Context Managers

Of all of the most commonly used Python constructs, context managers are neck-and-neck with decorators in a "Things I use but don't really understand how they work" contest. As every schoolchild will tell you, the canonical way to open and read from a file is:

with open('what_are_context_managers.txt', 'r') as infile:
    for line in infile:
        print('> {}'.format(line))

But how many of those who correctly handle file IO know why it's correct, or even that there's an incorrect way to do it? Hopefully a lot, or else this post won't get read much...

Read on →


Improve Your Python: the with Statement and Context Managers

Of all of the most commonly used Python constructs, context managers are neck-and-neck with decorators in a "Things I use but don't really understand how they work" contest. As every schoolchild will tell you, the canonical way to open and read from a file is:

with open('what_are_context_managers.txt', 'r') as infile:
    for line in infile:
        print('> {}'.format(line))

But how many of those who correctly handle file IO know why it's correct, or even that there's an incorrect way to do it? Hopefully a lot, or else this post won't get read much...

Read on →


Python Dictionaries

Aside: one thing I dislike about the official Python documentation is that only a small percentage of entries have example code. We should change that...)

One of the keys to becoming a better Python programmer is to have a solid grasp of Python's built-in data structures. Using the structured format below, today you'll learn what a dict is, when to use it, and see example code of all of its member functions. I have some other data structures in the works, so this may turn into a little series.

Read on →


Flask and SQLAlchemy Magic

For my first "real" post after my extended leave, I wanted to cover something fun (well, fun if you like writing libraries with Flask and SQLAlchemy...). In one of my projects at work recently, I was tasked with turning a client-facing Flask app that I had written into a framework/library that made creating new "sub-applications" as easy as possible. One pattern that had worked well in the original app was the use of Flask-SQLAlchemy, both for interacting with a new set of database models and in connecting to existing databases owned by other teams. One existing database, in particular, was heavily used by the app and would likely be used a good deal by any "sub-apps" created on the framework.

The database in question was essentially our company's "main" database, with about 100 tables (each with thousands or millions of records). This is a common, and somewhat frustrating situation when writing internal libraries: you know clients are going to need to use some resource, but you're not exactly sure how or what parts of it. How do you create an interface to that? With SQLAlchemy specifically, does that mean each sub-project will need to describe all of the tables it needs to use from the "main" database, leading to repeated, boilerplate code? Of course not! All it takes is a little magic.

Read on →


Web Analytics