Include bash script in python compilation
Question: I have a couple of bash scripts that I use in a Python program. The current
solution is to browse to the file in the GUI and then run the script(s) like
this (`pathToScript` is the String for the path to the script):

    
    
    INPUT = [pathToScript, input1, input2, input3, input4, input5, input6, input7, input8, input9, input10]
    subprocess.call(INPUT)
    

To avoid always browsing to the script or hard coding the path, I am looking
for a solution to somehow include the bash script in the compiled Python
program and then run it inside the program. Is this possible? I'd rather not
rewrite the bash scripts to Python if I can avoid it.


Answer: You can always bundle the bash script with the rest of your program (like I
suspect you are already doing), and reconstruct the path to these scripts at
runtime.

It is easy enough to get the location of any python module from within the
module itself, then create path to the bash script from there:

    
    
    import os.path
    
    LOCATION = os.path.dirname(os.path.abspath(__file__))
    pathToScript = os.path.join(LOCATION, 'bashscript.sh')
    

and `pathToScript` would then be an absolute path to the file `bashscript.sh`
sitting in the same directory as the current Python module.

