Search code examples
pythonenvironment-variablesjuliatransfer

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

  • 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)