Improve Your Python: 'yield' and Generators Explained

Posted on by

Prior to beginning tutoring sessions, I ask new students to fill out a brief self-assessment where they rate their understanding of various Python concepts. Some topics ("control flow with if/else" or "defining and using functions") are understood by a majority of students before ever beginning tutoring. There are a handful of topics, however, that almost all students report having no knowledge or very limited understanding of. Of these, "generators and the yield keyword" is one of the biggest culprits. I'm guessing this is the case for most novice Python programmers.

Many report having difficulty understanding generators and the yield keyword even after making a concerted effort to teach themselves the topic. I want to change that. In this post, I'll explain what the yield keyword does, why it's useful, and how to use it.

Read on →


And Now for Something Completely Different...

Posted on by

For those who noticed, I apologize for the radio silence over the past month. I've been preoccupied with job related activities, which I can discuss at long last. I've decided to leave my current position (and the finance industry all-together). Monday the 25th, I'll be joining AppNexus, a recognized leader in the online ad tech space. I'll be joining the "Data Platform Services" team, which is charged with making the 10s of TB of data (generated daily) accessible to the rest of the organization. It's very much a "big data" problem.

I'm extremely excited about this for a number of reasons. The company is experiencing explosive growth, the people are smart and passionate, and the work is incredibly interesting (to me). I'm also looking forward to growing professionally; I've basically been working on the same thing (between two banks) since graduating college. I have learned a ton in that time, but the "learning vs. time" graph has been trending downward for the past few years. I'm reinvigorated at the notion of working on something completely new (which still makes use of my experience building high-throughput, low-latency systems).

In other news...

On another note, I'm happy to be leaving finance. I'll discuss this a bit more in a few weeks, but for now I'll simply say that financial technology jobs are quite different than technology positions in almost every other sector. This change has been long-overdue for me, and I appreciate the opportunity I've been given.

Anyway, look for my next Python related post (which I've been working on for some time) to appear in the next few days. Also, for those that subscribe to my newsletter, the project I discussed with all of you a few weeks ago is gaining momentum. Look for more news on that front in the coming weeks. And last, but not least, the next version of Writing Idiomatic Python, which contains a ton of new content, should be available in the next few weeks. Lots of stuff to look forward to (for both you and I)!

Read on →


Drastically Improve Your Python: Understanding Python's Execution Model

Posted on by

Those new to Python are often surprised by the behavior of their own code. They expect A but, seemingly for no reason, B happens instead. The root cause of many of these "surprises" is confusion about the Python execution model. It's the sort of thing that, if it's explained to you once, a number of Python concepts that seemed hazy before become crystal clear. It's also really difficult to just "figure out" on your own, as it requires a fundamental shift in thinking about core language concepts like variables, objects, and functions.

In this post, I'll help you understand what's happening behind the scenes when you do common things like creating a variable or calling a function. As a result, you'll write cleaner, more comprehensible code. You'll also become a better (and faster) code reader. All that's necessary is to forget everything you know about programming...

Read on →


Write Cleaner Python: Use Exceptions

Posted on by

Many programmers have had it drilled into their head that exceptions, in any language, should only be used in truly exceptional cases. They're wrong. The Python community's approach to exceptions leads to cleaner code that's easier to read. And that's without the monstrous hit to performance commonly associated with exceptions in other languages.

Read on →


Anatomy of an eBook Launch: Raw Numbers

Posted on by

On January 24th, I officially "launched" my eBook Writing Idiomatic Python. I had no idea what to expect and even less of an idea about what I should do to promote it. So I did the easiest thing: posted to reddit (/r/python to be specific). Aside from a post to hacker news not about the book itself and a single tweet, posting on reddit was the only thing I did.

And that was enough.

The post got a few upboats and stayed on the front page of /r/python for 5 days (and was the top post for about 2 days). The traffic, from reddit alone mind you, sold a lot of books (the exact numbers are discussed later).

Read on →