JuliaREPL中仅允许有限输出的选项是什么?

结果变量是一个json类型的字符串,很长。当变量这么长时,Julia REPL 中有什么选项只允许有限的输出?DataFrame 最初只是部分输出。我希望通用变量也能这样输出。

回答

您可以覆盖s的display方法AbstractString

import Main.display
display(x::AbstractString) =
           show(length(x)<=50 ? x : SubString(x,1,50)*"…")

让我们测试一下:

julia> str = join(rand('a':'z', 200))
"wcbifwzglgqyenrcdgdxagohlwdoxrrumoaltklkjauptwzrmi…"

  • I've opened an issue to discuss doing this out of the box: https://github.com/JuliaLang/julia/issues/40724. The implementation there also avoids being O(ncodeunits(str)), which is important for *really* long strings.
  • Put it into Julia startup file! Here is how: https://stackoverflow.com/questions/52175314/where-is-juliarc-the-julia-startup-file/52175490#52175490

以上是JuliaREPL中仅允许有限输出的选项是什么?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>