Hard to find bugs, misleading exceptions

Chermside, Michael mchermside at ingdirect.com
Tue Feb 25 15:59:52 CET 2003


> >>> l=[
> ...  (1,2),
> ...  (3,4),
> ...  (5,6)  # note missing comma
> ...  (7,8)
> ... ]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: 'tuple' object is not callable

(1) Use pychecker. (If it doesn't catch this problem,
  it SHOULD.)

(2) Also, type it like this:

    el = [
        (1,2),
        (3,4),
        (5,6),
        (7,8),   # note USE of comma
    ]

  The use of a comma after EVERY element, instead of
  every one but the last, will save you lots of bugs
  like this when cutting-and-pasting or adding new
  items to the list. Fortunately, it's LEGAL syntax
  in Python (although not, unfortunately, in C, Java,
  and some other things I have to work with).

-- Michael Chermside






More information about the Python-list mailing list