[Python-bugs-list] [ python-Bugs-422669 ] Bug with appending objects to list.
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 09 May 2001 08:17:55 -0700
Bugs item #422669, was updated on 2001-05-09 08:17
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=422669&group_id=5470
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Pavel Khmelinsky (russhmepas)
Assigned to: Nobody/Anonymous (nobody)
Summary: Bug with appending objects to list.
Initial Comment:
Please, excuse me if this problem is problem of my brain and not a bug....
1st source:
*******************
>>> class cl:
... i = 0
... def grown(self):
... self.i = self.i + 1
...
...c = cl()
...db = []
...j = 0
...for i in range(0, 10):
... c.grown()
... db.append(c)
... print vars( db[j] )
... j = j + 1
{'i': 1}
{'i': 2}
{'i': 3}
{'i': 4}
{'i': 5}
{'i': 6}
{'i': 7}
{'i': 8}
{'i': 9}
{'i': 10}
*****************
All rights!
Lets try to see whats the members of the list "db" after end of cycle:
*****************
>>> class cl:
... i = 0
... def grown(self):
... self.i = self.i + 1
...
... c = cl()
... db = []
... for i in range(0, 10):
... c.grown()
... db.append(c)
...
... for j in db:
... print vars(j)
{'i': 10}
{'i': 10}
{'i': 10}
{'i': 10}
{'i': 10}
{'i': 10}
{'i': 10}
{'i': 10}
{'i': 10}
{'i': 10}
********************
Why!? Why all members of list are similiar?
This problem doesn'n exist if I appending to list a sipmle type variable (like integer), not
a class object.
P.S.: Sorry for my English, my 1st language is Russian.
P.P.S.: I am using W2k professional
Regards,
Pavel Khmelinsky
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=422669&group_id=5470