Python - Julia 变量传输

发布于 2025-01-16 05:08:48 字数 267 浏览 4 评论 0原文

假设我有一个包含 python 和 julia 的 jupyter 笔记本。在 julia 中我有一个变量

var_julia = 10

,在 python 中我有

var_python = 20

我想做的是有效地(没有任何 JSON 或 CSV)在这两个变量之间传输,这样我就可以在 python 中打印 var_julia 并在 julia 中打印 var_python 。我该怎么做呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜妞爱困 2025-01-23 05:08:48

基本上使用前面提到的 PyCall PyJulia 你可以这样做:

var_python = 10

%%julia
py"var_python"

反之亦然:

var_julia = 20

new_var = %julia var_julia
print(new_var)

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)
源来凯始玺欢你 2025-01-23 05:08:48

查看 PythonCall 和 JuliaCall ,它应该涵盖您的用例。

还有用于“从 Julia 调用 Python”方向的 PyCall.jlPyJulia 用于“从 Python 调用 Julia”方向。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文