Include compiled C file into Python.

huangapple go评论61阅读模式
英文:

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:

  1. 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?
  2. 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:

  1. 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?
  2. 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

huangapple
  • 本文由 发表于 2023年4月13日 22:02:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76006363.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定