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

Neamus
  • 198
  • 2
  • 15
  • Do you want to call single functions from your c file or do you want to call a compiled program? – FlyingTeller Aug 15 '18 at 09:28
  • single functions. I would like every button to be unique. – Neamus Aug 15 '18 at 09: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`](https://docs.python.org/3/library/subprocess.html) module can help. – 9769953 Aug 15 '18 at 09: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](https://stackoverflow.com/q/89228/1782792). 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?](https://stackoverflow.com/q/9420673) on that topic). – jdehesa Aug 15 '18 at 09:31

1 Answers1

4

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

Umair Khalid
  • 98
  • 1
  • 6