[New-bugs-announce] [issue7800] Attributes of type list are static

Chris Carter report at bugs.python.org
Fri Jan 29 00:58:38 CET 2010


New submission from Chris Carter <jesdisciple at gmail.com>:

The test case at the end of this message seems to indicate that the list is being initialized only once for all wrapper instances.  I've tried to find anything about static members in Python and came up empty.  I also found no relevant existing bugs.

Expected output:
0 [0]
1 [1]
2 [2]
3 [3]

Actual output:
0 [0]
1 [0, 1]
2 [0, 1, 2]
3 [0, 1, 2, 3]

Test case:
i = 0
class Lister:

        list = []
        string = ""
        def __init__(self):
            global i
            self.list.append(i)
            self.string += str(i)
            i += 1
        def __str__(self):
            return "%s %s" % (self.string, self.list)

print Lister()
print Lister()
print Lister()
print Lister()

----------
components: Interpreter Core
messages: 98483
nosy: Chris.Carter
severity: normal
status: open
title: Attributes of type list are static
versions: Python 2.6

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


More information about the New-bugs-announce mailing list