manipulating files within 'for'

bearophileHUGS at bearophileHUGS at
Fri Sep 12 20:50:20 CEST 2008

Ben Keshet:
> ...wrong.  I thought I should omit the comma and didn't put it.  I guess
> that stating the obvious should be the first attempt with beginners like
> me.  Thanks for thinking about it (it's running perfect now).

In CLisp, Scheme etc, lists such commas aren't necessary, but in
Python if you don't separate strings with a comma they become merged
into a single string:

>>> 'foo', 'bar'
('foo', 'bar')
>>> 'foo' 'bar'

Your mistake is caused by Python not following one of its general

Explicit is better than implicit.

In such case the string concatenation (+) is done implicitly. It's a
little handy feature once in a while (but not for me so far), while it
may cause bugs, so I don't like this little feature of Python and I
may like to see it removed, because it may bite you in similar
situations, where you forgot a comma for mistake:

parts = ["foo", "bar" "baz"]


More information about the Python-list mailing list