0

Edit<<<<<<<
The question is:

-How do you launch C code from python? (say, in a function)
-How do you load Java code into python? (perhaps in a class?)
-Can you simply work with these two in a python program or are there special considerations?
-Will it be worth it, or will integrating cause too much lag?

Being familiar with all three languages (C, Java and Python) and knowing that Python supports C libraries, (and apparently can integrate with Java also) I was wondering if Python could integrate a program using both languages?

What I would like is fast flexible C functions while taking advantage of Java's extensive front-end libraries and coordinating the two in Python's clean, readable syntax.

Is this possible?

EDIT----> To be more specific, I would like to write and execute python code that integrates my own fast C functions. Then, call Java libraries like swing to create user interface and handle networking. Probably taking advantage of XML as well to aid in file manipulation.

Kijewski
  • 25,517
  • 12
  • 101
  • 143
  • If your only goal is to integrate Java and C, using Python doesn't spring to mind as the obvious choice, given the existence of e.g. [SWIG](http://en.wikipedia.org/wiki/SWIG). – Oliver Charlesworth Aug 29 '14 at 23:27
  • Obviously it can. For example, if you expose your Java code through a REST service, you can write CPython code that uses `ctypes` to talk to the C code and `urllib` to talk to the Java code. Or if you compile your Java code with J# and expose your C code via COM, you can write an IronPython script that talks to both directly. And so on. Do you have a more specific question? Like, for example, do you want to access C libraries from Jython without going through JNI? – abarnert Aug 29 '14 at 23:27
  • sounds like CPython and Jython at the same time; though i would skip python completly and go with JNI bridge; why add an extra prog lang, that doesn't make it easier. – Seismoid Aug 29 '14 at 23:33
  • Yes. It's possible. No. It's not easy. – Elliott Frisch Aug 29 '14 at 23:33
  • It doesn't have to be easy as long as it is fluid. Ie. if I'm going to lose so much in speed by integrating, then I may as well have not written it in C. They must communicate well, I was thinking APIs. – stackoverflow101 Aug 29 '14 at 23:34
  • Could you perhaps explain how it would be done the way I have described? Or some other way if it will be fluid/ – stackoverflow101 Aug 29 '14 at 23:47

2 Answers2

1

To be more specific, I would like to write and execute python code that integrates my own fast C functions. Then, call Java libraries like swing to create user interface and handle networking. Probably taking advantage of XML as well to aid in file manipulation.

Integrating C code into Python is quite easy using modules such as ctypes or cffi.

Integrating Java code into Python is not simple, and is likely well beyond your ability. There are plenty of very capable user interface, networking, and XML processing libraries available for Python; you don't need Java to do any of that.

  • Would you mind surmising the steps it would take to bring java into python? I thought python had apis for java? – stackoverflow101 Aug 30 '14 at 00:46
  • It's not something that's often particularly useful (or sensible) to do, but see: http://stackoverflow.com/q/3652554/149341 –  Aug 30 '14 at 01:00
1

For C, you can use ctype module or SWIG.

For Java, Jython is a good choice.