【问题标题】:Capturing and displaying output from within Julia从 Julia 中捕获和显示输出
【发布时间】:2017-06-14 13:00:23
【问题描述】:

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

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

即:

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

【问题讨论】:

    标签: julia stdio


    【解决方案1】:

    答案就在这里:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-08
      • 1970-01-01
      相关资源
      最近更新 更多