A weblog by Will Fitzgerald

Monthly Archives: February 2009

Epoch success

The 1234567890 Epoch captured on the web!

Things that are wrong with Python (3): destructive functions

Pythons’s sort and append functions mutate the sequence they work on.

This is wrong. Rather than write x = list.append(1).sort() you have to write:
x = list[:]

Things that are wrong with Python (2): return values

Python doesn’t return values by default.

This is wrong. The last value should always be returned.

Things That Are Wrong with Python (1): True and False

The following values are all false in Python programming language.

  1. None
  2. False
  3. numbers equal to 0: 0, 0L, 0.0, 0j
  4. empty sequences:e.g., ‘””, (), [], array.array(‘i’)
  5. empty maps: e.g., {}
  6. any object that defines a __nonzero__ or __len__ method (returning False or len=0, respectively

This is a Thing that is Wrong with Python.

(The Right Way: false is None or False; everything else is true.)

(Note: I really do disagree with this design decision, but I’m mostly writing this down so I will remember not to write code like this:

if object.table: print 'table was initialized'

but instead remember to write:

if object.table and len(object.table)>0: print 'table was initialized'

Epoch odometer