I have a file named test7.tcl:
namespace eval ::dai {
variable name "ratzip"
variable birthday "1982"
proc hello {} {
variable name
variable birthday
puts "Hello, I am $name birthday is $birthday"
}
}
and I want to source this file into another file, called test8.tcl in this way:
source test7.tcl
::dai::hello
but it gives me error: couldn’t read file “test7.tcl”: no such file or directory
but the two files are under the same folder, what happened?
To source a file that is in the same directory as the currently executing script, use this:
Note that this doesn’t work inside procedures defined inside the outer script (test8.tcl in your case) because they’re typically called after the source finishes. If that’s the case for you, the simplest fix is to just save the output of
info scriptin a variable in your outer script (or just source all files immediately instead of lazily for the ultimately best approach).