[Solved] Class constructor able to init with an instance of the same class object


Not sure what you’re trying to achieve, but technically your error is here:

    self = kwargs.get('object',self)

There’s nothing magic with self, it’s just a function argument, and as such a local variable, so rebinding it within the function will only make the local name self points to another object within the function’s scope. It’s in no way affecting the current instance (the one that was passed to __init__ by the method wrapper), it just makes self an alias for object.

If what you want is to copy attributes from object to self, you have to do it explicitly:

 other = kwargs.get('object')
 if other is not None:
     self.attrx = other.attrx
     self.attry = other.attry
     # etc

Oh and yes: Python is high-level language, there’s nothing like “address affectation” – all you have are names refering to objects (really, name=>object mapping). A name is just a name, and where the object actually lives is none of your concerns.

2

solved Class constructor able to init with an instance of the same class object