Lie a écrit : > On Dec 22, 6:18 am, Bruno Desthuilliers > <[EMAIL PROTECTED]> wrote: > >>Lie a écrit : >>(snip) >> >> >>># Python have an odd (read: broken) singleton implementation >>># single member tuple must have a comma behind it >> >>You may call it weird or even a wart if you want, but given that what >>makes the tuple is the comma - not the parens[1] -, it is _not_ broken. >> >>[1] with the exception of the empty tuple. > > > I also realized that you don't need to use parens to make tuple, it's > rather my habit to always use parens in making a tuple
FWIW, almost anybody does so except in a couple cases (mostly related to tuple unpacking). First because it's more readable, and also because - as you noticed - there are cases where you need the parens to force evaluation order. > PS: My wording on broken doesn't actually means broken so it won't > work, but rather broken syntactically, making the syntax inconsistent, > funny, illogical, etc. One could argue though that the trailing comma > is a formalized workaround. The problem is that there are not so many "grouping" characters available, and that parens end up being used for too many things: function call operator, function arguments definitions, evaluation order (grouping) and the empty tuple (and now generator expressions). I guess this would make it impractical for the parser to have to distinguish between grouping and literal tuples. So while I agree it's a bit weird, it's not illogical - once you get the logic !-) -- http://mail.python.org/mailman/listinfo/python-list