Blog

  • Why you should almost never use “is” in Python

    It’s really tempting, when you first start to use Python, to use “is” rather than “==”.  It’s a bit more readable, and it feels like it should just work, especially when you’re dealing with integers. In a language that uses “or” and “and” instead of “||” and “&&”, it seems logical to use “is” instead…

    Read more

  • Free Webinar on June 23rd: Introduction to Regular Expressions

    If you’re a programmer, then you have likely heard about regular expressions (“regexps”) before. However, it’s also likely that you have tried to learn them, and have found them to be completely confusing. That’s not unusual; while regular expressions provide us with a powerful tool for analyzing text, their terse, dense, and cryptic syntax can…

    Read more

  • New ebook: Jewish guide to visiting China

    As many people know, I’ve visited China seven times over the last three years, traveling there to give courses in Python and Ruby. I just got back from my most recent trip, and found it to be as fun and exciting as ever. You could say that I’ve gotten a bit obsessed with the country;…

    Read more

  • Free one-hour Webinar about Python’s magic methods on May 6th

    I’ll be giving another free one-hour Webinar about Python — this time, about the magic methods that Python offers developers who want to change the ways in which their objects work. We’ll start off with some of the simplest magic methods, but will quickly move onto some of the more interesting and advanced ones —…

    Read more

  • Is it hashable? Fun and games with hashing in Python

    One of the basic data types that Python developers learn to use, and to appreciate, is the dictionary, or “dict.” This is the Python term for what other languages call hashes, associative arrays, hashmaps, or hash tables. Dictionaries are pervasive in Python, both in the programs that we write, and in the implementation of the…

    Read more

  • Free Webinar in object-oriented Python on April 1st, 2015

    Join me for an hour-long free Webinar about object-oriented Python on April 1st, 2015. I’ll discuss how to use and create classes in Python, how attributes form the core of Python’s object system, and how you should (and shouldn’t) think about Python’s objects. There will be plenty of time for Q&A. Come and join me;…

    Read more

  • How not to write an error message

    Users and programmers see error messages very differently. When a user sees an error message, they think, “Oh, no.  Something went wrong.”  Rarely, in my experience, does the user think to read the error message, or to use it as a clue toward what might have happened.  Technology is so opaque, so hard to understand,…

    Read more

  • A quick introduction to implementing Python iterators

    When you put a piece of Python data into a “for” loop, the loop doesn’t execute on the data itself.  Rather, it executes on the data’s “iterator.”  An iterator is an object that knows how to behave inside a loop. Let’s take that apart.  First, let’s assume that I say: for letter in ‘abc’:    …

    Read more

  • If you don’t use “with”, when does Python close files? The answer is: It depends.

    One of the first things that Python programmers learn is that you can easily read through the contents of an open file by iterating over it: f = open(‘/etc/passwd’) for line in f:     print(line) Note that the above code is possible because our file object “f” is an iterator. In other words, f…

    Read more

  • My latest side project: DailyTechVideo.com, posting new conference videos every day

    If you’re like me, you love to learn. And in our industry, a primary way of learning involves attending conferences. However, if you’re like me, you never have the time to actually attend them.  (In my case, the fact that I live far away from where many conferences take place is an additional hindrance.) Fortunately,…

    Read more