Mutable objects in python and constants
Question: I have a class which contains data as attributes and which has a method to
return a tuple containing these attributes:

    
    
    class myclass(object):
        def __init__(self,a,b,c):
            self.a = a
            self.b = b
            self.c = c
    
        def tuple(self):
            return (self.a, self.b, self.c)
    

I use this class essentially as a tuple where the items (attributes) can be
modified/read through their attribute name. Now I would like to create objects
of this class, which would be constants and have pre-defined attribute values,
which I could then assign to a variable/mutable object, thereby initializing
this variable object's attributes to match the constant object, while at the
same time retaining the ability to modify the attributes' values. For example
I would like to do this:

    
    
    constant_object = myclass(1,2,3)
    variable_object = constant_object
    variable_object.a = 999
    

Now of course this doesn't work in python, so I am wondering what is the best
way to get this kind of functionality?


Answer: 
    import copy
    
    class myclass(object):
        def __init__(self,a,b,c):
            self.a = a
            self.b = b
            self.c = c
    
        def tuple(self):
            return (self.a, self.b, self.c)
    
    constant_object = myclass(1,2,3)
    variable_object = copy.deepcopy(constant_object)
    variable_object.a = 999
    print constant_object.a
    print variable_object.a
    

Output:

    
    
    1
    999
    

