'Python - Julia variables transfering

Let's say I have a jupyter notebook with both python and julia. In julia i have a variable

var_julia = 10

and in python I have

var_python = 20

What I would like to do is to efficiently (without any JSONs nor CSVs) transfer these 2 variables between, so I can print var_julia in python and var_python in julia. How should I do that?



Solution 1:[1]

Basically using the forementioned PyCall PyJulia you can do:

var_python = 10

%%julia
py"var_python"

and for the other way round:

var_julia = 20

new_var = %julia var_julia
print(new_var)

Solution 2:[2]

Have a look at PythonCall and JuliaCall which should cover your use case.

There's also PyCall.jl for the "call Python from Julia" direction and PyJulia for the "call Julia from Python" direction.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 coder1122
Solution 2 Nils Gudat