-1

I have a Source code in C, I want to write it in Python. I have .so library files for my C code, is it possible to change .so files to .py lib files for execution?

If so, how can I execute my python files? I mean in order to run C in python, we use something like below:

gcc -shared -I/usr/include/python2.3/ -lpython2.3 -o myModule.so myModule.c

So is there is something like this to execute my python files or can I just use import command to execute?

Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
A A Ron
  • 3
  • 1
  • 3
    It isn't clear to me whether you're asking to access dynamically linked libraries from python, or whether you're porting C code to python and are just wondering how python's module system works – Trevor Merrifield Sep 07 '16 at 22:48

1 Answers1

1

You can use Python's ctypes module to load so files and use their functions.
Take a look at the second answer here.

Community
  • 1
  • 1
galah92
  • 3,621
  • 2
  • 29
  • 55
  • I'm newbie to programming, Started off with learning Python. Apologies if my question wasn't clear. I will re-write the source code (viz in C) to Python. But, I later realized that just writing the code in python will not be enough as the lib files for my C code are in C. My question is How should i execute my python code when the libraries are written in C? I do have .so and .a files in the lib. – A A Ron Sep 07 '16 at 22:54
  • @AARon, you are still very unclear. If you have an `so` file that you want to excute via Python, it's quite easy using `ctypes`. Other methods of translating C code to python are definitely less productive. – galah92 Sep 07 '16 at 23:03
  • Ok. Thanks a lot.. Yes, I have an so file and I want to execute it via Python, so i'll take a look at Python's types. – A A Ron Sep 07 '16 at 23:37