从 Julia 中捕获和显示输出

Capturing and displaying output from within Julia

我到处找这个,所以我把它放在这里给疲惫的旅行者;

问题:如何从 julia 脚本中将变量的完整输出捕获到文件中?

即:

#script.jl
y = f(x)
y > out.txt

答案在这里:

https://github.com/JuliaLang/IJulia.jl/issues/455 如果要显示输出,则:

show(STDOUT, "text/plain", x)

如果要将输出通过管道传输到文件,则:

x=rand(Float32, 32,32)
f = open("log.txt", "w")
    write(f, string(x))
close(f)

对于更大的 x 或更漂亮的输出

x = rand(Float32, 1028,1028);
f = open("log.txt", "w");
writedlm(f, x);
close(f);