I need to transfer information between two Julia files (or: between two Jupyter notebooks). Examples of data structures:
- A dictionary with keys “a”, “b”, “c”, etc., where the value for each key is a tuple holding Floats, dates, interpolation functions, etc.
- It is kind of ugly to write this into a *.jl file to include the file in the other document.
Question: is there a simpler way? Can I store the data in a Json file and read the JSON file in the other document? If so:
- Which package?
Example: suppose I have the following data structure:
using Dates, DataInterpolations
#
x = 3
t = Date(2020,11,5)
X = 0:20
Y = sin.(X*2pi/10)
y = ConstantInterpolation(Y,X)
#
d = Dict("a" => (x,t,y))
# ...
merge(d,Dict("b") => ...)
If I want to store this as a *.jl file, I cannot save/write the dictionary d
, but instead need to build it up from scratch in write statements… something like:
open("my_dictionary.jl", "w") do f
write(f,"t_y = $(Year(t).value) \n")
write(f,"t_m = $(Month(t).value) \n")
write(f,"t_d = $(Day(t).value) \n")
write(f,"X = $(X) \n")
write(f,"Y = $(Y) \n")
#
write(f,"y = ConstantInterpolation(Y,X) \n")
write(f,"d = Dict("a",($(x),Date(t_y,t_m,t_d),y)) \n")
end
When I run this code, I can include the file in another Jupyter notebook, and get back the dictionary:
using Dates, DataInterpolations, Plots
include("my_dictionary.jl")
plot(d["a"][3])
I assume there is a simpler way, so that I only need to write something like
save("my_dictionary",$d)
or something like this…
But what is the best package to do this?