Fredrik Lundh a écrit :
> Christophe wrote:
> 
> 
>>I think you've made a mistake in your example.
> 
> 
>      >>> constant A = []
>      >>> def foo(var):
>      ...     var.append('1')
>      ...     print var
>      ...
>      >>> b = A
>      >>> foo(b)
>      >>> foo(b)
> 
> 
>>>and this ?
>>>
>>>    >>> constant A = []
>>>    >>> print A is A
>>
>>Obviously, False.
> 
> 
> why obviously ? why shouldn't a constant be constant ?
> 
> </F> 

Because the name A is bound by the compiler to mean construct a new 
object since [] is mutable.

Same reason why :

 >>> def A(): return []
 >>> print A() is A()
False

It gives btw one possible implementation ;)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to