[New-bugs-announce] [issue9092] static behavior of local variables

Konstantin report at bugs.python.org
Sun Jun 27 16:27:52 CEST 2010


New submission from Konstantin <kaslanidi at yahoo.com>:

In [12]: def func(x=[]) :
   ....:     L=x
   ....:     L.append('a')
   ....:     return L
   ....:

In [13]: func()
Out[13]: ['a']

In [14]: func()
Out[14]: ['a', 'a']

In [15]: func()
Out[15]: ['a', 'a', 'a']

In [16]: func()
Out[16]: ['a', 'a', 'a', 'a']

In [17]: x
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)

C:\Users\konstantin\<ipython console> in <module>()

NameError: name 'x' is not defined

In [18]:

In [19]: L
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)

C:\Users\konstantin\<ipython console> in <module>()

NameError: name 'L' is not defined

----------
components: None
messages: 108789
nosy: Aslanidi
priority: normal
severity: normal
status: open
title: static behavior of local variables
type: behavior
versions: Python 2.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9092>
_______________________________________


More information about the New-bugs-announce mailing list