Idiomatic Python: functions versus classes

In Python, everything is an object. Compared to Java which forces you to code everything in an object-oriented programming style but still has the concept of primitive types which are not objects on their own (although Java 5 added autoboxing to help hide this discrepancy), Python has no primitive types which aren’t objects but provides the…

1

Idiomatic Python: EAFP versus LBYL

One idiomatic practice in Python that often surprises people coming from programming languages where exceptions are considered, well, exceptional, is EAFP: “it’s easier to ask for forgiveness than permission”. Quickly, EAFP means that you should just do what you expect to work and if an exception might be thrown from the operation then catch it…

4

Idiomatic Python: boolean expressions

You might think that boolean expressions — most frequently used as conditional guards which are the the bit of code that tests whether an if or while statement should execute — are a fairly straight-forward concept and that there isn’t really anything subtle to them at all. And while the general concept is simple, there…

3

Idiomatic Python: comprehensions

We’re lucky to have a few people on our team who have been programming in Python for quite a while (I myself have been using the language now for over 15 years). Over the course of time we have picked up various idioms for programming in Python that may not be obvious or widely known…

4