You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use yaml files to store my simulation parameters and I am commenting every line. Sometimes I need to change values from a software and not manually. Then the comments would get lost. To avoid this I wrote some helper functions which are not very generic:
# modify a variable in a yaml file# read as textfunctionreadfile(filename)
open(filename) do file
readlines(file)
endendfunctionwritefile(lines, filename)
open(filename, "w") do file
for line in lines
write(file, line, '\n')
endendendfunctionchange_value(lines, varname, value::Union{Integer, Float64})
change_value(lines, varname, repr(value))
endfunctionchange_value(lines, varname, value::String)
res = String[]
for line in lines
ifstartswith(lstrip(line), varname)
start = (findfirst(varname, line)).stop+1
stop =findfirst('#', line)-1
new_line =""
leading =true
j =1for (i, chr) inpairs(line)
if i < start || i > stop
new_line *= chr
elseif line[i] ==''&& leading
new_line *=''elseif j <=length(value)
new_line *= value[j]
j +=1
leading =falseelseif i <= stop
new_line *=''endendpush!(res, new_line)
elsepush!(res, line)
endend
res
end
Would it make sense to add something like this to this package or to the documentation?
The text was updated successfully, but these errors were encountered:
I would 100% accept a PR to add this as an example in the docs.
Being able to round-trip with comments would certainly be nice, but I don't know how complicated it would be to do so in a robust way. Happy to accept proposals though.
I use yaml files to store my simulation parameters and I am commenting every line. Sometimes I need to change values from a software and not manually. Then the comments would get lost. To avoid this I wrote some helper functions which are not very generic:
Would it make sense to add something like this to this package or to the documentation?
The text was updated successfully, but these errors were encountered: