In Python, you can use setattrto add a new attribute to an object, such as the following code
class Foobar:
def __init__(self):
pass
foobar = Foobar()
setattr(foobar, 'foo', 123)
print(foobar.foo)
Output
123
I know Julia has setfield! but it does not allow adding a new type field setattrin Python.
so my question is is there a way to add a new field to an object of a composite type?
Mis94 source
share