accessing elements of a tuple

Steven D'Aprano steven at
Sun Feb 1 20:06:53 EST 2009

On Sun, 01 Feb 2009 09:32:42 -0500, D'Arcy J.M. Cain wrote:

> On Sun, 01 Feb 2009 19:23:58 +1100
> Steven D'Aprano <steve at> wrote:
>> D'Arcy J.M. Cain wrote:
>> > First of all, list is a reserved word.  Don't use it as a variable
>> > name.
>> Unless you mean to. Shadowing built-ins is only a bad thing when you do
>> it by accident.
> I suppose but I am having a hard time trying to think of some good
> reason to replace a builtin function that creates a list with a list
> object.
>>>> list = list((1,2,3))
>>>> list((1,2,3))
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: 'list' object is not callable

There may not be a positive reason in favour of it, but in a small 
function that doesn't call list() and never will, there's no reason 
*against* using the name 'list'. Sometimes generic names like 'list' (or 
if you prefer, 'alist') are sensible, and in those cases, shadowing the 
list built-in may be a matter of taste.

I personally don't like it, but some people obviously do.


More information about the Python-list mailing list