I have the following working directory from which I am running ankiAdd.py - in this script at one point i'm accessing the 'internal API' of another python program elsewhere on my hard drive in order to use some of those functions. I would like to get the working directory where 'ankiAdd.py' is stored however I kept retrieving another directory.
The following snippet is a function within my ankiAdd.py script. Collection is imported from another directory on my hard drive in which another program Anki is installed. I'd like the file_pattern variable to give the directory of this script and not the directory of cpath, which is currently happening.
sys.path.append("C:/Users/Shaun/Documents/Personal_Projects/ankiExperiment/anki-scripting/anki")
from anki.storage import Collection
PROFILE_HOME = os.path.expanduser("C:/Users/Shaun/Desktop/User 1")
cpath = os.path.join(PROFILE_HOME, "collection.anki2")
@eel.expose
def callLoad():
col = Collection(cpath, log=True)
json_pattern = "word_data.json"
file_pattern = os.path.join(os.getcwd(),json_pattern)
load(col,file_pattern)
I've tried numerous things like os.getcwd() and os.path.dirname(os.path.realpath(file)) however I kept ending up retrieving C:\Users\User\Desktop\User 1\collection.media which is the location of cpath. How can I get the directory of ankiAdd.py which is the script which was originally run?
edit:
def callLoad():
col = Collection(cpath, log=True)
json_pattern = "word_data.json"
print(os.path.dirname(os.path.realpath(__file__)))
file_pattern = os.path.join(os.getcwd(),json_pattern)
#load(col,file_pattern)
if __name__ == '__main__':
callLoad()
if I run this code, the directory returned is C:\Users\Shaun\Desktop\User 1\collection.media which is the directory set by this at the top of my file:
PROFILE_HOME = os.path.expanduser("C:/Users/Shaun/Desktop/User 1")
I am running the script from

