Bugs item #1229264, was opened at 2005-06-28 21:47 Message generated for change (Comment added) made by birkenfeld You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1229264&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: None Group: Python 2.3 >Status: Closed >Resolution: Invalid Priority: 5 Submitted By: ST2015 (st2015) Assigned to: Nobody/Anonymous (nobody) Summary: error whit dict working whith class Initial Comment: se follow code: """ class my_class: a={} def __init__(self, n): self.a = n def hola(self, b): self.a["a"] = b a1 = my_class({"a":1, "b":1}) print "a1=", a1.a a2 = my_class({"a":1, "b":1}) a1.hola(2) print "a2=", a2.a print "a1=", a1.a """ must show: a1= {'a': 1, 'b': 1} a2= {'a': 1, 'b': 1} a1= {'a': 2, 'b': 1} but show: a1= {'a': 1, 'b': 1} a2= {'a': 2, 'b': 1} a1= {'a': 2, 'b': 1} This error happend only whit dicts, y only when de dict atributte is defined before of the __init__ of the class ---------------------------------------------------------------------- >Comment By: Reinhold Birkenfeld (birkenfeld) Date: 2005-06-28 22:01 Message: Logged In: YES user_id=1188172 Then this is no bug. You are never assigning to self.a, thus the "a" you reference in the class's methods is the one defined as a class attribute and therefore shared between instances. ---------------------------------------------------------------------- Comment By: ST2015 (st2015) Date: 2005-06-28 21:54 Message: Logged In: YES user_id=1304338 sorry the code is the folowing: class my_class: a={} def __init__(self, n): for i in n: self.a[i] = n[i] def hola(self, b): self.a["a"] = b a1 = my_class({"a":1, "b":1}) print "a1=", a1.a a2 = my_class({"a":1, "b":1}) a1.hola(2) print "a2=", a2.a print "a1=", a1.a ---------------------------------------------------------------------- Comment By: ST2015 (st2015) Date: 2005-06-28 21:54 Message: Logged In: YES user_id=1304338 sorry the code is the folowing: class my_class: a={} def __init__(self, n): for i in n: self.a[i] = n[i] def hola(self, b): self.a["a"] = b a1 = my_class({"a":1, "b":1}) print "a1=", a1.a a2 = my_class({"a":1, "b":1}) a1.hola(2) print "a2=", a2.a print "a1=", a1.a ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1229264&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com