How to read/process tuple data file

I have saved some data in Julia without any thought for formatting it. The saved file look something like the following;

([0.123, 0.124, ... ,0.999], [0.222, 0.223, ..., 0.999])

Link: Perc_SARW_analysis/data_files/datfile_100x100_75l_10^4.txt at main · tushargayan2324/Perc_SARW_analysis · GitHub

Can someone tell me how to parse the text file as tuple in Julia?

It’s bad practice in general, but for a once-off to fix a mistake you could do:

str = readchomp(filename)
t = eval(Meta.parse(str))
1 Like

I’d recommend just using JLD2.jl.
You can just do:

julia> data = rand(10,10);

julia> JLD2.jldsave("data.jld2"; data=data)

julia> JLD2.load("data.jld2")
Dict{String, Any} with 1 entry:
  "data" => [0.636269 0.0650003 … 0.758512 0.482105; 0.385604 0.769785 … 0.3141…

julia> data2 = JLD2.load("data.jld2")["data"]; data == data2
true
1 Like