Hi there,
I have a file called file.txt, with the following contents:
N_questions = 4
ini_window = "2021-04-10 14:00"
I will use the variables N_questions and ini_window later on, in a (long) Julia script I named include_within_function.jl, which starts like:
using Dates
function build_df(file)
include(file)
if !(isinteger(N_questions) && N_questions > 0)
error("N_questions must be a positive integer.")
end
dtformat = DateFormat("y-m-d H:M")
ini_window = DateTime(ini_window, dtformat)
end
After declaring
file = "file.txt"
include("include_within_function.jl")
and then
build_df(file)
I get the error:
ERROR: UndefVarError: ini_window not defined
Sorry for the silly question, but: Why is it the variable N_questions is recognized (since the if loop issues no error), while the ini_window variable is not? I am almost sure it is a matter of scope, but am not able to figure it out! I say this because, when I run the statements of the body of the build_df function outside it, the variable ini_window is defined…
Could someone give me a nice detailed and pedagogical explanation for this behavior, with examples, if possible?
PS: On a parenthetical note, I would also appreciate suggestions as to the best way for Julia to digest parameters or variables provided in an ascii file instead of includeing it, as for the file.txt above.