Closed jfdev001 closed 3 months ago
Hi @jfdev001,
saving a dictionary as a via save(file, dict)
interprets the keys very similarly to how an operating system uses file paths.
Slashes indicate folders / groups. A leading slash refers to the root
group which is fully redundant here.
The convention upon loading is to not prepend the slash everywhere.
julia> d = Dict("a" => 1, "/b" => 2, "c/d/e" => 3)
Dict{String, Int64} with 3 entries:
"c/d/e" => 3
"/b" => 2
"a" => 1
julia> save("test.jld2", d)
julia> f = jldopen("test.jld2")
JLDFile /home/jisensee/test.jld2 (read-only)
├─🔢 b
├─🔢 a
└─📂 c
└─📂 d
└─🔢 e
If you really want to store a dict with string keys that contain /
then, you could use e.g.
julia> save("test.jld2", "dict_dataset", d)
julia> f = jldopen("test.jld2")
JLDFile /home/jisensee/test.jld2 (read-only)
└─🔢 dict_dataset
julia> f["dict_dataset"]
Dict{String, Int64} with 3 entries:
"c/d/e" => 3
"/b" => 2
"a" => 1
Note, that the former logic allows you to load/access parts of the dict individually while the latter does not.
Perhaps I am missing something obvious here, but if I have a dictionary whose entries begin with a backslash
"/"
, when saving and subsequently loading the JLD2 file, the backslash is lost. Is this expected behavior?and the output is