I have a python script that could up end up in different directories on different servers. My script has sys.path.insert line where it look's for libraries and also looks for config.ini file in the same directory as the script. I want to be able to run the script with the full path.
example.py:
#!/usr/local/bin/python3.6
import sys, getopt, configparser
sys.path.insert(0, '../lib/')
from myFunctions import mySendmail, remoteFileChkSum, sendfile
...
def main():
    config = configparser.ConfigParser()
    # username and encrupted passwords are in config.ini
    # keys for encryption are in .keys
    config.read('config.ini')
    config.read('.keys')
On some hosts the file is in /export/apps/bin/ with the lib folder in /export/apps/lib. On other hosts it's in /export/home/ray/bin with the lib folder in /export/home/ray/lib.
What is the best practice so I can run the script from anywhere on any host?? Should I find the directory/location of the script at the beginning and perform a os.chdir('<DIR>')?
 
    