First import dirname
and join
from the os.path
module in config.py
:
from os.path import dirname, join
Then change CONF_FILE
to:
CONF_FILE = join(dirname(__file__), 'data', 'config.xml')
Think of __file__
as the absolute path to the file some code is defined in, at the time it is loaded as a module. dirname
takes that path and gives you a path to the directory that file lives in, and join
strings together any number of arguments into a new path.
So first we would get {abs_path_to}root/server/config.py
by reading __file__
. Then dirname(__file__)
gets us to {abs_path_to}root/server
. Joining that with data
and then config.xml
finally gives us {abs_path_to}root/server/data/config.xml
.