Creating classes and objects more than once?
Diez B. Roggisch
deets at nospam.web.de
Thu Nov 27 12:54:20 EST 2008
Viktor Kerkez wrote:
> Here is the situation:
>
> $ ls
> test
> $ cd test
> $ ls
> __init__.py data.py
> $ cat __init__.py
>
> $ cat data.py
> DATA = {}
>
> $ cd ..
> $ python
>>>> import os
>>>> from test.data import DATA
>>>> DATA['something'] = 33
>>>> os.chdir('test')
>>>> from data import DATA as NEW_DATA
>>>> DATA
> {'something': 33}
>>>> NEW_DATA
> {}
>
>
> Is this a bug?
No. You create an alias NEW_DATA in your local scope, but that alias still
points to the same object, a dictionary.
Diez
More information about the Python-list
mailing list