So I have a python script my_script.py which is inside the folder Test and I am outside this folder. The script requires to access some input data from the file my_data.dat stored inside the folder Test. 
Now, when I try to run this script from outside the folder Test, using simple python my_script.py, it tries to locate my_data.dat in the folder from which I am running the script and so fails. How can I tell it use the correct path without actually modifying the path in the my_script.py? 
I don't want to modify the paths in the script because the script is to be used generically for various paths and the whole thing would be automated later.
You can either pass the path to my_data.dat as a parameter to the script, or (if the data file is always in the same directory as the  script) you can use the variable __file__ to determine where the script is and look for the data file in that directory.
Running python codes from outside the directory when script has filepaths