使用相同的密钥写入现有的 Julia 数据文件

Writing on an existing Julia data file with the same key

假设我们有一个 .jld 文件,它有两个键,"hi""bye" as

import JLD

file = JLD.jldopen("test.jld","a+")
     file["hi"] = randn(1)
     file["bye"] = randn(1)
JLD.close(file)

现在,如果我想用键 "hi" 更改保存在 test.jld 上的值并且不影响键 "bye" 的值,我该怎么办?

它尝试了下面的代码

file = JLD.jldopen("test.jld","a+")
     file["hi"] = randn(1)
JLD.close(file)

但它显示错误 Error creating dataset //hi

一旦您创建了 JLD 文件,您应该使用加载和保存来更改值,即

julia> using JLD

julia> filed = JLD.load("test.jld")
Dict{String,Any} with 2 entries:
  "bye" => [-0.275391]
  "hi"  => [-0.869752]

julia> filed["hi"] = randn(1)
1-element Array{Float64,1}:
 -0.3132472191308679

julia> JLD.save("test.jld", filed)

julia> filed = JLD.load("test.jld")
Dict{String,Any} with 2 entries:
  "bye" => [-0.275391]
  "hi"  => [-0.313247]