Assume that we have an object k of type class A. We defined a second class B(A). What is the best practice to “convert” object k to class B and preserve all data in k?
Assume that we have an object k of type class A . We defined
Share
This does the “class conversion” but it is subject to collateral damage. Creating another object and replacing its
__dict__as BrainCore posted would be safer – but this code does what you asked, with no new object being created.