Extra comma (was Re: For review: PEP 308 - If-then-else expression)

Oren Tirosh oren-py-l at hishome.net
Wed Feb 12 05:10:00 EST 2003


On Tue, Feb 11, 2003 at 01:07:08PM -0800, Russell E. Owen wrote:
> In article <mailman.1044738743.29728.python-list at python.org>,
>  Tim Peters <tim.one at comcast.net> wrote (answering somebody who noted 
> the neat ability to have a trailing comma in lists):
> 
> >...When I'm in a hurry, it's
> >surprising how often I forget to add a trailing comma to the preceding item
> >when appending a new item, so in containers I expect to grow I always use a
> >trailing comma.  Then adding a new item usually consists of duplicating the
> >last line verbatim and just editing the parts that change...
> >
> >For the life of me, though, I've never found a good reason to add a trailing
> >comma to a formal argument list.
> 
> I second that. Python is one of the few languages I know that permits an 
> extra comma at the end of lists and such. I use this all the time for 
> essentially the same reasons you mention. I can safely add or delete 
> items without worrying about the last one being special.

There is a slight inconsistency in Python in that it doesn't allow a
trailing comma in an empty list, tuple or argument list. 1-tuples REQUIRE 
a comma and 0-tuples FORBID a comma. If would have been more consistent
to always allow a trailing comma. My sense of order and pattern always
found this slightly irritating.

	Oren





More information about the Python-list mailing list