How to add a new field to Julia type?

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?

+4
source share
1 answer

Is there a way to add a new field to an object of a composite type?

. . , . Julia - Dict - . , , Python, , Julia, - , .

+10

Source: https://habr.com/ru/post/1672201/


All Articles