You are viewing a read-only archive of the Blogs.Harvard network. Learn more.
Skip to content

Python gotchas

Got this link from Ted Leung on Python Programming pitfalls. Looks like an interesting read and explains some of the more subtle behaviours of Python.
The gotcha below I find really irksome:

>>> t = ([],)
>>> t[0] += [2, 3]
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: object doesn't support item assignment
>>> t
([2, 3],)

A tuple is an immutable (aka it shouldn’t be able to be changed) object in Python. The += operator throws up a warning but goes ahead and changes it anyways. Ummm… that’s dumb. But all programming languages have their own sets of
annoyances. My personal pet peeve with Python is that it’s really hard to integrate into the pipeline like Perl or Ruby.

Be Sociable, Share!