0

I am mainly using python for extensive algorithms operations. Now i have my webiste in Django.

I few libraries in c++ and few in Java which i don't have in python. Or you can say that i already have some c++ , Java files in which some algorithm is coded.

can i call those function or do some calculation in my djnago sites using those c++ or java files

user776358
  • 33
  • 1
  • 7

3 Answers3

2

For C++, certainly. Either write a module that wraps the library, or use something like ctypes or SWIG.

For Java, you'd be best to move to Jython (and correspondingly use django-jython).

Note that using both C++ and Java from Python is not trivial.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • sorry but my english is not so good so u mean not trivial means not easy means difficult. So u mean people r not using it – user776358 Jun 01 '11 at 11:12
  • It takes a decent amount of both knowledge and skill to be able to bridge C++, Java, and Python. – Ignacio Vazquez-Abrams Jun 01 '11 at 11:14
  • It might be possible to compile the Java code to native library with gjc and use the C method on it, but even if the library actually compiles, it would still be hard. – Jan Hudec Jun 01 '11 at 11:19
  • ok , but i will not be using it initially , i was just asking if thats possible or not. Actuaaly i want to implement Genetic algiriths and optimaztion algos in python , i have books in java and c++ which explains the code and working but not in python. so i thought i need arises i can bridge them. there are libraries in python as well but i want to code myself – user776358 Jun 01 '11 at 11:21
  • The only way for a novice to get this working is to use Jython instead of Python to call Java methods. As long as you don't have the Java code (but only the text in the book) I suggest to simply rewrite it in Python. That should be easy. – Angel O'Sphere Jun 01 '11 at 11:43
0

You could check the http://www.scipy.org/Weave weave package for C/C++. I didn't use it myself, but I know it exists

0

I've used Boost.Python to some degree of success for accessing C++ libraries within Python/Django.

Steve Walsh
  • 6,363
  • 12
  • 42
  • 54