Is there a commas-in-between idiom?

Magnus Lycka lycka at carmen.se
Thu Nov 9 10:01:06 CET 2006


Ernesto García García wrote:
> list = [1,2,3,4,5,6]

Just a nit-pick: It's considered an anti-idiom
to hide builtins just as list by using it as a
name for a variable.

 >>> list=[1,2,3,4,5]
 >>> tuple = (1,2,3,4,5)
 >>> if list == list(tuple): print "equal"
...
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
TypeError: 'list' object is not callable
 >>> #ouch!
...
 >>> l=list
 >>> del list
 >>> if l == list(tuple): print "equal"
...
equal
 >>> if tuple(l)==tuple: print "equal"
...
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
TypeError: 'tuple' object is not callable
 >>> t=tuple
 >>> del tuple
 >>> if tuple(l)==t: print "equal"
...
equal



More information about the Python-list mailing list