Thanks, much nicer!
You can set header = ["x", "y"]
for this:
julia> using Tables, CSV
julia> CSV.write("file.csv", Tables.table([1 2]), header=["x", "y"])
"file.csv"
julia> print(read("file.csv", String))
x,y
1,2
Personally I think that, if you can choose your file format you might not want CSV if this is a configuration file with a header and never more than one row of values.
Instead, an ini-like format like TOML is preferable to a tabular format for configuration because itβs more flexible. For example to create some configuration and write it to the file:
julia> using TOML
julia> config = Dict("x"=>1, "y"=>2, "z"=>[4,5,6])
Dict{String,Any} with 3 entries:
"x" => 1
"z" => [4, 5, 6]
"y" => 2
julia> open(io->TOML.print(io, config), "config.toml", write=true)
Hereβs the content of the generated βconfig.tomlβ
julia> print(read("config.toml", String))
x = 1
z = [4, 5, 6]
y = 2
Now you can read it back in and refer to the variables by name, relative to the config Dict:
julia> config_read = open(io->TOML.parse(io), "config.toml")
Dict{String,Any} with 3 entries:
"x" => 1
"z" => [4, 5, 6]
"y" => 2
julia> config_read["x"]
1
julia> config_read["y"]
2
julia> config_read["z"]
3-element Array{Int64,1}:
4
5
6
Notice how this allows a lot of flexibility in having nested structures of Dicts
and Arrays
for your program configuration.