Python: stray commas cause tuples?

Published on Oct. 15, 2010, 11:26 a.m.

As I try to debug a strange problem in a Django view, I notice a stray comma after a dictionary definition. So I jump over to a python shell, and guess what? Ending a literal dict with a comma creates a tuple.
>>> d = {1:'foo'},
>>> type(d)
<type 'tuple'>
>>> d
({1: 'foo'},)

comments powered by Disqus