I run the below script via command line: julia script.jl
.
# file name: script.jl
a = 1
b = 2
c = a + b
varinfo()
My problem is that the varinfo() does not run in terminal, i get the following error:
ERROR: LoadError: UndefVarError: 'varinfo' not defined
.
How can i show at the end of my run the status of all variables in the script when i run the script in commandline?
This function and some others are primarily intended for interactive use and are loaded by default in an interactive session. To see where it comes from you can do this.
julia> @which varinfo
InteractiveUtils
You can load InteractiveUtils
explicitly in your script to make varinfo
available.
using InteractiveUtils
a = 1
b = 2
c = a + b
println(varinfo())
2 Likes
Thank you so much @GunnarFarneback
An extra question.
how can i print all the variables and their value ?
varinfo()
only prints the variables name, size, and type.
I don’t know about anything that does that out of the box but you can do something yourself like
for var in names(Main)
value = getfield(Main, var)
if value isa Number
println(var, " = ", value)
end
end
1 Like