Maybe so?
Basic approach
config.txt,
A=1.0
B = 2.1
C= 3.3
D =4.4
, , Dict, :
julia> vars = Dict{String, Float64}()
Dict{String,Float64} with 0 entries
julia> f = open("config.txt")
IOStream(<file config.txt>)
julia> for line in eachline(f)
var, val = split(line, "=")
vars[strip(var)] = parse(Float64, val)
end
julia> vars
Dict{String,Float64} with 4 entries:
"B" => 2.1
"A" => 1.0
"C" => 3.3
"D" => 4.4
julia> vars["A"]
1.0
, , :
julia> vars = Dict{String, Float64}()
Dict{String,Float64} with 0 entries
julia> allowed = ["A", "B", "C"]
3-element Array{String,1}:
"A"
"B"
"C"
julia> f = open("config.txt")
IOStream(<file config.txt>)
julia> for line in eachline(f)
var, val = split(line, "=")
stripped = strip(var)
if stripped in allowed
vars[stripped] = parse(Float64, val)
end
end
julia> vars
Dict{String,Float64} with 3 entries:
"B" => 2.1
"A" => 1.0
"C" => 3.3
D=... config.txt , allowed.
, Dict
:
function go(;A=0.0, B=0.0, C=0.0)
println("A = $A, B = $B, C = $C")
end
vars = Dict{Symbol, Float64}()
f = open("config.txt")
allowed = ["A", "B", "C"]
for line in eachline(f)
var, val = split(line, "=")
stripped = strip(var)
if stripped in allowed
vars[Symbol(stripped)] = parse(Float64, val)
end
end
go(;vars...)
config.txt
A = 1.0, B = 2.1, C = 3.3