Is it possible in python to recreate an object from already instatiated object, with all it's arguments passed into __init__
method?
Something similar to inspect.getcallargs
, but for class instances.
For example:
class A:
def __init__(self, some_arg):
self.some_arg = some_arg
def f(a):
# somehow get all arguments from `a`, with which it was created
# kwargs = ...?
# and create a new instance of class with the same (or modified) args:
return a.__class__(**kwargs)
a = A(100)
new_a = f(a)
print(new_a.some_arg)
>>> 100