This code:
import os
dn = os.path.dirname(os.path.realpath(__file__))
sets "dn" to the name of the directory containing the currently executing script. This code:
fn = os.path.join(dn,"vcb.init")
fp = open(fn,"r")
sets "fn" to "script_dir/vcb.init" (in a platform independent manner) and opens that file for reading by the currently executing script.
Note that "the currently executing script" is somewhat ambiguous. If your whole program consists of 1 script, then that's the currently executing script and the "sys.path[0]" solution works fine. But if your app consists of script A, which imports some package "P" and then calls script "B", then "P.B" is currently executing. If you need to get the directory containing "P.B", you want the "os.path.realpath(__file__)
" solution.
"__file__
" just gives the name of the currently executing (top-of-stack) script: "x.py". It doesn't
give any path info. It's the "os.path.realpath" call that does the real work.