Bugs item #1652387, was opened at 2007-02-05 13:35 Message generated for change (Comment added) made by gbrandl You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1652387&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: Build Group: Python 2.5 >Status: Closed >Resolution: Invalid Priority: 5 Private: No Submitted By: kkelchev (kkelchev) Assigned to: Nobody/Anonymous (nobody) Summary: Nested Objects scope problem Initial Comment: K = MyObj() K.Lines.append('First line to Obj "K"') K.Lines.append('Second line to Obj "K"') L = MyObj() L.Lines.append('First line to Obj "L"') print 'Lines from Obj "K"',K.Lines print 'Lines from Obj "L"',L.Lines Result is: [Dbg]>>> Lines from Obj "K" ['First line to Obj "K"', 'Second line to Obj "K"', 'First line to Obj "L"'] Lines from Obj "L" ['First line to Obj "K"', 'Second line to Obj "K"', 'First line to Obj "L"'] >>> Why data appended into nested list filed “Lines” into different object “K” and “L” appears in both objects ? ---------------------------------------------------------------------- >Comment By: Georg Brandl (gbrandl) Date: 2007-02-05 18:31 Message: Logged In: YES user_id=849994 Originator: NO Sadly you didn't attach the definition of the class "MyObj". I assume it is like this: class MyObj: Lines = [] In this case, the Lines list object is shared by all instances of MyObj. Please post to the python-list mailing list for further questions about this behavior. If your bug is different, please feel free to reopen this. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1652387&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com