Common pitfalls when using template files/support files in the working dir of the script, is easy to miss when you are writing command line tools. In this case using
python. Some of the more annoying mistakes is when you have template files stores and referred to in a script, you assume that the person that will use you script stands in the folder were the script is. lest assume that we are using a file template.html in a folder named foobar. of corse this will not work if you are running the script from somewhere else. I normally stand in the same folder as the script when i am developing a tool. When you then stand in some other folder everything will fail since you are not giving the absolute path to the template files.
there is a few option here and it’s to either only work if you standing in the correct folder, fix the paths to work anyway, or last a install script that creates the env you need and have a static path that can be used in any system.
you have a few options here were to store scripts and template/files that you need to read in linux.
i will assume that you want a custom script with a support template file. the script should be for all users. that means the script should be stored in
/usr/local/bin and i will store the support template in a subfolder in
/usr/share. this is how i can look to accomplish that. first i remove the old files and then write the new version.
one other option is if you don’t want to install the script but still like to call the script from anywhere and still have template files working. you can use
os.path.dirname(os.path.abspath(__name__)) in the python script to give the working dir of the script, and then using that to add to the path of template files. this is how it can look