在Go项目文件夹中运行python脚本(使用脚本的项目/相对文件路径)

I am trying to execute a python script in Go. However, everywhere I look, nothing explains how to execute the script using the project/relative path. I have my code on GitHub and don't want the full path to the script ("home/user/Documents/projectFolder/script.py)

Instead, I need a project/relative path ("/script.py" or equivalent)

Ultimately, how do I execute the script.py, without having to go look for it in a specific directory?

NOTE: my project is in "home/user/Documents/project"

edit: changed 'Ultimately' section

With Go being a compiled language, which (normally) results in a single executable, the project structure is pretty much lost at compile-time. Therefore a project relative path is meaningless at run-time. You would need another way to find your script (as well as get it to the one executing your program).

One way of doing this is to require, that your executable and the script are in locations you know relative to one another (e.g. a scripts folder and a bin folder which are in the same directory). Then you can os.Args[0] to get the path to your executable, which you can then use to construct the path to your script. To construct the path, you can take a look at the filepath package.

Edit: After reading your updated question, I found the packr project, which seems to provide a way to include static files in your binary. I never used the project and do not know how to use it exactly, but it appears that you should be able to store your script file in your binary and then, pass the script to python in some way. For example, you could write it to a temporary file or pass it to python using the -c argument. This approach will require you to build your project using the packr command-line tool. Also, if you include big files, your binary will also grow in size.