[ python-Bugs-1229264 ] error whit dict working whith class

SourceForge.net noreply at sourceforge.net
Tue Jun 28 21:54:08 CEST 2005


Bugs item #1229264, was opened at 2005-06-28 15:47
Message generated for change (Comment added) made by st2015
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: Open
Resolution: None
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: ST2015 (st2015)
Date: 2005-06-28 15: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


More information about the Python-bugs-list mailing list