I'm trying to run a Python script (A) from within another Python script (B), where the scripts are in different directories. The directory that script A is stored in is variable and is stored in a JSON file in script B's directory, something like this:
/documents
/directory-a
script-a.py
/directory-b
script-b.py
script-info.json
To make matters more complicated, script A's filename is variable too. Currently my code for script-b.py is something like this:
import sys
import json
with open("script-info.json") as json_file:
directory = json.load(json_file)["directory"]
filename = json.load(json_file)["filename"]
sys.path.append(directory)
import filename
Using sys.path.append
and import
in the middle of my program feel like workarounds and import filename
doensn't work since filename is stored as a string.
Thanks in advance for any help!