classification
Title: strange list.sort() behavior on import, del and inport again
Type: Stage:
Components: Versions: Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: dstemmer, loewis
Priority: normal Keywords:

Created on 2009-05-01 04:51 by dstemmer, last changed 2009-05-01 06:31 by loewis. This issue is now closed.

Files
File name Uploaded Description Edit
bugs.rar dstemmer, 2009-05-01 04:51
Messages (2)
msg86862 - (view) Author: David Stemmer (dstemmer) Date: 2009-05-01 04:51
Given two modules, I've seen the following kind of strange behavior with
list sorting on import and delete; a list that has been imported, sorted
and deleted remains sorted on a second import:

my_module.py:

some_list = ['b','a']

other_module.py:

from  my_module import some_list
print some_list
some_list.sort()
print some_list
del some_list
from  my_module import some_list
print some_list

Output is:

['b','a']
['a','b']
['a','b']

Sorry if it's already been reported.
msg86865 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-05-01 06:31
That is not a bug in Python. The import statement merely adds a
reference to the list into your module, so both variables point to the
very same list (my_module.some_list is other_module.some_list).
Therefore, any changes made to the list through my_module will also
affect the list as seen from other_module.

Closing the report as invalid.
History
Date User Action Args
2009-05-01 06:31:53loewissetstatus: open -> closed

nosy: + loewis
messages: + msg86865

resolution: not a bug
2009-05-01 04:51:58dstemmercreate