Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to use python code from Scala (or Java)? [duplicate]

Possible Duplicate:
Java Python Integration

There is some code written in Python and I need to use it from Scala. The code uses some native C. Is it possible to use this from Scala or Java without having to rewrite much?

I intend to use the code as a black-box without understanding, so I prefer not to look into it but rather to somehow generate a jar that I can import in my code.

like image 811
Jus12 Avatar asked Jun 04 '12 13:06

Jus12


People also ask

Which is best Scala or Python?

Performance. When it comes to performance, Scala is the clear winner over Python. One reason Scala wins on performance is that it is a statically typed programming language and Python is a dynamically typed programming language. With statically typed languages, the compiler knows each variable or expression at runtime.

Can we call Python code from Scala?

It works from the command line because the shell is parsing and interpreting the string before invoking the python command. In the Scala code the ProcessBuilder is trying to parse and interpret the string without the shell's help. We can help the interpreting. This should work.

What is the advantage of Scala in Python?

Scala allows writing of code with multiple concurrency primitives whereas Python doesn't support concurrency or multithreading. Due to its concurrency feature, Scala allows better memory management and data processing. However Python does support heavyweight process forking.

Which is faster Python or Scala?

PerformanceScala, a compiled language, is seen as being approximately 10 times faster than an interpreted Python because the source code is translated to efficient machine representation before the runtime.


1 Answers

Why not try Jython?You directly compile python code to Java classes or call Python code from Java through interface.

like image 116
Petr Mensik Avatar answered Oct 23 '22 17:10

Petr Mensik