0

I want to create a function inside a class that replaces itself with a copy of another object of that class. A very rudimentary example is given below, but this seems too manual and imagine it might have other problems like not copying over new methods.

Is there a pythonic way of doing this?

class MyClass:
    def __init__(self,a,b):
        self.a=a
        self.b=b

    def Replaceme(self,NewCls):
        self.a=NewCls.a
        self.b=NewCls.b
martineau
  • 119,623
  • 25
  • 170
  • 301
Miguel
  • 1,293
  • 1
  • 13
  • 30
  • 1
    don't give functions such names `Replaceme` – RomanPerekhrest Oct 05 '17 at 21:32
  • See [**_Function Names_**](https://www.python.org/dev/peps/pep-0008/#function-names) in the [PEP 8 - Style Guide for Python Code](https://www.python.org/dev/peps/pep-0008/) (although you _may_ get a pass this time since the name is `Replaceme` `;-)`—except `NewCls` is also not the recommended letter-casing to use for variable names) – martineau Oct 05 '17 at 21:54

0 Answers0