Jun-01-2020, 10:32 AM
using os, I usually set my starting directory as the directory containing the script,
then set everything relative from there using pathlib.
the os command I issue during script initialization is:
then using pathlib, immediately after that:
then set everything relative from there using pathlib.
the os command I issue during script initialization is:
os.chdir(os.path.abspath(os.path.dirname(__file__)))
then using pathlib, immediately after that:
# add at top with other imports: from pathlib import Path ... # somewhere in initialization: homepath = Path('.') base_path = homepath / '..' / 'data'Once this is established, you can set relative paths from there
widgetpath = base_path / 'widgets' zingo_widgetfile = widgetpath / 'zingo.dat' with zingo_widgetfile.open() as fp: zingodata = fp.read()etc.