<p>In Python is there any way to make a class, then make a second version of that class with identical dat,a but which can be changed, then reverted to be the same as the data in the original class? </p>

<p>So I would make a class with the numbers 1 to 5 as the data in it, then make a second class with the same names for sections (or very similar). Mess around with the numbers in the second class then with one function then reset them to be the same as in the first class. </p>

<p>The only alternative I've found is to make one aggravatingly long class with too many separate pieces of data in it to be readily usable.</p>

[{'answer_id': 64163, 'author': 'Teifion', 'author_id': 1384652, 'author_profile': 'https://Stackoverflow.com/users/1384652', 'pm_score': 4, 'selected': True, 'text': '<p>A class is a template, it allows you to create a blueprint, you can then have multiple instances of a class each with different numbers, like so.</p>\n\n<pre><code>class dog(object):\n    def __init__(self, height, width, lenght):\n        self.height = height\n        self.width = width\n        self.length = length\n\n    def revert(self):\n        self.height = 1\n        self.width = 2\n        self.length = 3\n\ndog1 = dog(5, 6, 7)\ndog2 = dog(2, 3, 4)\n\ndog1.revert()\n</code></pre>\n'}, {'answer_id': 64195, 'author': 'Håkan', 'author_id': 8420, 'author_profile': 'https://Stackoverflow.com/users/8420', 'pm_score': 1, 'selected': False, 'text': "<p>Classes don't have values. Objects do. Is what you want basically a class that can reset an instance (object) to a set of default values? </p>\n\n<p>How about just providing a reset method, that resets the properties of your object to whatever is the default?</p>\n\n<p>I think you should simplify your question, or tell us what you really want to do. It's not at all clear.</p>\n"}, {'answer_id': 64206, 'author': 'eordano', 'author_id': 8393, 'author_profile': 'https://Stackoverflow.com/users/8393', 'pm_score': 1, 'selected': False, 'text': '<p>I think you are confused. You should re-check the meaning of "class" and "instance".</p>\n\n<p>I think you are trying to first declare a Instance of a certain Class, and then declare a instance of other Class, use the data from the first one, and then find a way to convert the data in the second instance and use it on the first instance...</p>\n\n<p>I recommend that you use operator overloading to assign the data.</p>\n'}, {'answer_id': 64216, 'author': 'Drag0n', 'author_id': 8433, 'author_profile': 'https://Stackoverflow.com/users/8433', 'pm_score': 1, 'selected': False, 'text': '<pre><code>class ABC(self):\n   numbers = [0,1,2,3]\n\nclass DEF(ABC):\n   def __init__(self):\n      self.new_numbers = super(ABC,self).numbers\n\n   def setnums(self, numbers):\n      self.new_numbers = numbers\n\n   def getnums(self):\n     return self.new_numbers\n\n   def reset(self):\n     __init__()\n</code></pre>\n'}, {'answer_id': 64399, 'author': 'pobk', 'author_id': 7829, 'author_profile': 'https://Stackoverflow.com/users/7829', 'pm_score': 1, 'selected': False, 'text': "<p>Just FYI, here's an alternate implementation... Probably violates about 15 million pythonic rules, but I publish it per information/observation:</p>\n\n<pre><code>class Resettable(object):\n    base_dict = {}\n    def reset(self):\n            self.__dict__ = self.__class__.base_dict\n\n    def __init__(self):\n            self.__dict__ = self.__class__.base_dict.copy()\n\nclass SomeClass(Resettable):\n    base_dict = {\n            'number_one': 1,\n            'number_two': 2,\n            'number_three': 3,\n            'number_four': 4,\n            'number_five': 5,\n    }\n    def __init__(self):\n            Resettable.__init__(self)\n\n\np = SomeClass()\np.number_one = 100\nprint p.number_one\np.reset()\nprint p.number_one\n</code></pre>\n"}, {'answer_id': 82969, 'author': 'Steve Losh', 'author_id': 13498, 'author_profile': 'https://Stackoverflow.com/users/13498', 'pm_score': 2, 'selected': False, 'text': "<p>Here's another answer kind of like pobk's; it uses the instance's dict to do the work of saving/resetting variables, but doesn't require you to specify the names of them in your code.  You can call save() at any time to save the state of the instance and reset() to reset to that state.</p>\n\n<pre><code>class MyReset:\n    def __init__(self, x, y):\n        self.x = x\n        self.y = y\n        self.save()\n\n    def save(self):\n        self.saved = self.__dict__.copy()\n\n    def reset(self):\n        self.__dict__ = self.saved.copy()\n\na = MyReset(20, 30)\na.x = 50\nprint a.x\na.reset()\nprint a.x\n</code></pre>\n\n<p>Why do you want to do this?  It might not be the best/only way.</p>\n"}]
['https://Stackoverflow.com/questions/64141', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8324/']