[ python-Bugs-1549499 ] bug in classlevel variabels

SourceForge.net noreply at sourceforge.net
Wed Aug 30 20:44:31 CEST 2006


Bugs item #1549499, was opened at 2006-08-30 20:44
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1549499&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Thomas Dybdahl Ahle (thomasda)
Assigned to: Nobody/Anonymous (nobody)
Summary: bug in classlevel variabels

Initial Comment:
class A:
    js = []
    
    def add (self, j):
        self.js.append(j)

    def clone (self):
        c = A()
        for j in self.js:
            c.add(j)
        return c

a = A()
b = a.clone()
b.add(3)

print a.js
print b.js

The above code should print "[]\n[3]", but instead it
prints "[3]\n[3]"!

It works as expected, if you change "js = []" to "def
__init__ (self):
        self.js = []"

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1549499&group_id=5470


More information about the Python-bugs-list mailing list