Check that the read()
method returns a non-empty list otherwise it means that settings.ini
is not found. Relative paths are resolved relative to the current working directory (place where you've run python
), not script's directory (where bar.py
is stored).
You should probably use appdirs.user_config_dir()
, to get the directory where to put user's configuration files. Different OSes such as Windows, macOS, Linux distributions may use different defaults. appdirs
follows conventions that are appropriate for a given OS.
If you want to get data stored in a file that is packaged with your installed Python modules then you could use pkgutil.get_data()
or setuptools' pkg_resources.resource_string()
that work even if your package is inside an archive. It is not recommended to construct the paths manually but if you need the directory with the current script then you could put get_script_dir()
function into your scriptβit is more general than os.path.dirname(os.path.abspath(__file__))
. If the relative position is always the same then you could use:
#!/usr/bin/env python
import os
import subprocess
import sys
main_script_dir = os.path.join(get_script_dir(), os.pardir)
subprocess.check_call([sys.executable, '-m', 'main'], cwd=main_script_dir)
See Python : How to access file from different directory