[Tipz] unintended tuples in python

Mark Logan mlogan at ccs.neu.edu
Thu May 1 11:43:46 EDT 2003


If you use python, here's something super-annoying to
be aware of:

Python 2.2 (#1, Feb  3 2002, 02:44:52) 
[GCC 2.95.3 20010315 (release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> foo = 1,
>>> bar = 1
>>> print repr(foo)
(1,)
>>> print repr(bar)
1

That's right folks, you can turn any value into a 1-tuple by 
putting a comma at the end of the line.

Depending on how cluttered your source code is, how small your
font size is, and how tired you are, that little comma can take
hours to notice.

-Mark 


More information about the Tipz mailing list