Why copied objects have the same id as previously copied ones in Python?
Question: I am trying to understand one observation. I have an application that loads
various `Canvas` classes which a user can later work with. These classes are
located in several files. For example.

    
    
    canvas/
        bw.py
        colored.py
        oil.py
    

I import, instantiate and copy these objects like this:

    
    
    canvas_files = os.listdir('images')
    imported_canvs = []
        for canv in canvas_files:
            canv = __import__(canv.split('.')[0], fromlist=['Canvas'])
            try:
                new_canv = canv.Canvas()
                new_canv_copy = copy.copy(new_canv)
                imported_canvs.append(new_canv_copy)
            except AttributeError as ex:
                 pass
    

Afterwards, a user works with each `Canvas` object from `imported_canvs` list.
However, when I import and instantiate these objects twice (run the `for` loop
again) I can see `id(new_canv_copy)` is the same as previously imported and
instantiated ones. This would not be a problem unless that each `Canvas` has
settings which should be unique for each instance and this is not currently
happening. Whenever a user changes the settings in one `Canvas` they are
automatically changed in the copied one.

Why is this happening and what am I doing wrong?


Answer: Using just `copy.copy()` creates a shallow copy. You probably want to use deep
copy when copying objects using
[`copy.deepcopy()`](https://docs.python.org/2/library/copy.html#copy.deepcopy).

You can read in detail what's the difference here:
<https://docs.python.org/2/library/copy.html>

I don't know what `canv.Canvas()` does inside so it's hard to tell what's
going on when you run the same code twice when I can't try it by myself.

