JuliaCall: is it possible to pass objects from Python to Julia Main?

It’s admittedly not clear (I’ve now fixed this) but if you read down the full error stack the underlying error is:

AttributeError: Julia: cannot assign variables in other modules

which means that you can only assign a variable to a Julia module from code executing inside the module - this is a general Julia restriction.

If you really want you can write a function which uses @eval to do it:

>>> jlstore = jl.seval("(k, v) -> (@eval $(Symbol(k)) = $v; return)")
>>> jlstore("foo", [1,2,3])
>>> jl.foo
[1, 2, 3]
1 Like