From a YAML file I get the string “2.0:0.25:10.0”.
How can I convert it to a StepRange?
tsr="2.0:0.25:10.0"
TSR=eval(tsr) # not working
From a YAML file I get the string “2.0:0.25:10.0”.
How can I convert it to a StepRange?
tsr="2.0:0.25:10.0"
TSR=eval(tsr) # not working
I’d avoid eval and just parse the numbers from the string using nums = parse.(Float64,split(tsr,":"))
and then construct the range using those, range(nums[1],nums[3],step=nums[2])
gives:
ERROR: ArgumentError: StepRange should not be used with floating point
Stacktrace:
[1] steprange_last(start::Float64, step::Float64, stop::Float64)
@ Base .\range.jl:327
[2] StepRange{Float64, Float64}(start::Float64, step::Float64, stop::Float64)
@ Base .\range.jl:320
[3] StepRange(start::Float64, step::Float64, stop::Float64)
@ Base .\range.jl:373
[4] top-level scope
@ REPL[7]:1
range(nums[1],nums[3],step=nums[2])
should work
Thank you!
range(;zip((:start,:step,:stop),(parse.(Float64, split(tsr,':') )))...)# not
Yea, you are quoting code from my post that I didn’t write!
TSR=replace(tsr,':'=>',')
eval(Meta.parse("(:)("*TSR*')'))
or better
eval(Meta.parse(tsr))