英文:
Include compiled C file into Python
问题
I got a compiled C file (let's say testprog) from a person who is not here anymore, which takes 2 parameters when calling. They way I call the file from the unix shell is
testprog arg1 arg2
where arg1 is a file.
I am creating a GUI using python that generates the arg1 file easily instead of writing it manually. Now my questions are:
- How do I integrate the compiled C file into my python code, so that I can pass the unix command via python and get the results/output directly?
- How do I compile everything together (with the compiled C file) so that I can distribute my GUI to other people?
The final target will be providing a single file to users that incorporates my python gui and the compiled C
英文:
I got a compiled C file (let's say testprog) from a person who is not here anymore, which takes 2 parameters when calling. They way I call the file from the unix shell is
testprog arg1 arg2
where arg1 is a file.
I am creating a GUI using python that generates the arg1 file easily instead of writing it manually. Now my questions are:
- How do I integrate the compiled C file into my python code, so that I can pass the unix command via python and get the results/output directly?
- How do I compile everything together (with the compiled C file) so that I can distribute my GUI to other people?
The final target will be providing a single file to users that incorporates my python gui and the compiled C
答案1
得分: 1
For your 1st problem I recommend you checkout the subprocess
package.
import subprocess
output = subprocess.check_output(["testprog", "arg1", "arg2"])
or the ctypes package which allows you to call C functions from Python.
For the second problem, I think you will need to send both the Python and compiled C
for both of my solutions.
Edit:
Maybe checkout py_compile.
英文:
For your 1st problem I reccomend you checkout the subprocess
package.
import subprocess
output = subprocess.check_output(["testprog", "qrg1", "arg2"])
or the ctypes package which allows you to call c functions from python.
For the second problem, I think you will need to send both the python and compiled c
for both of my solutions.
edit:
Maybe checkout py_compile
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论