0

I made a GUI in Python and i just wanted to know how can i import a C file into python so every time a button is clicked on my GUI, different methods in the C program will be executed. I tried the 'Python' method of importing:

sys.path.insert(0, '/home/pi/Desktop/FTPclass.py')
import FTPclass

That worked for the python file i imported, but when I do the same for my c file, it complains saying my "testinc" module doesn't exist.

Thanks for everyone help in advance. ~Neamus

4
  • Do you want to call single functions from your c file or do you want to call a compiled program? Commented Aug 15, 2018 at 9:28
  • single functions. I would like every button to be unique. Commented Aug 15, 2018 at 9:29
  • "every time a button is clicked on my GUI, the C program will be executed": that sounds like you want to run the program as a separate executable (possibly passing additional input and capturing the output). Certainly if the GUI is just a layer on top of/wrapper around the C program. Perhaps the subprocess module can help. Commented Aug 15, 2018 at 9:31
  • In addition to the question linked in the previous comment (which is about calling C functions from Python), check out Calling an external command in Python. You may be able to compile our C code normally into a program and call that program from Python. What you definitely cannot do is executing uncompiled C code from Python (see Is it possible to compile c code using python? on that topic). Commented Aug 15, 2018 at 9:31

1 Answer 1

5

To use c file according to docs you need to first compile C code and then use the compiled file in your code

here is the link. Visit http://book.pythontips.com/en/latest/python_c_extension.html

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.