Hi!
I’m trying to write a simple text file where each line follows one of a few specific formats. Is it not permitted to use a variable to specify the format for @printf
? Example:
julia> fname = "abc"
"abc"
julia> @printf("%s %s", "File name: ", fname)
File name: abc
works fine but the following does not work:
julia> fmt = "%s %s"
"%s %s"
julia> fname = "abc"
"abc"
julia> @printf(fmt, "File name: ", fname)
ERROR: MethodError: no method matching format(::String, ::Printf.Format{Base.CodeUnits{UInt8, String}, Tuple{}}, ::String)
Closest candidates are:
format(::IO, ::Printf.Format, ::Any...) at ~/.julia/juliaup/julia-1.8.5+0.x64.apple.darwin14/share/julia/stdlib/v1.8/Printf/src/Printf.jl:820
format(::Printf.Format, ::Any...) at ~/.julia/juliaup/julia-1.8.5+0.x64.apple.darwin14/share/julia/stdlib/v1.8/Printf/src/Printf.jl:828
Stacktrace:
[1] top-level scope
@ REPL[41]:1
The same thing occurs with @sprintf
. Thanks for clarifications on this matter.