tags:

views:

296

answers:

3

Does a easy to use Ruby to Python bridge exist? Or am I better off using system()?

+2  A: 

I don't think there's any way to invoke Python from Ruby without forking a process, via system() or something. The language run times are utterly diferent, they'd need to be in separate processes anyway.

Charlie Martin
invoke processes via the subprocess module. system() lacks a lot, let's kill the beast.
nosklo
+5  A: 

You could try Masaki Fukushima's library for embedding python in ruby, although it doesn't appear to be maintained. YMMV

With this library, Ruby scripts can directly call arbitrary Python modules. Both extension modules and modules written in Python can be used.

The amusingly named Unholy from the ingenious Why the Lucky Stiff might also be of use:

Compile Ruby to Python bytecode.
And, in addition, translate that
bytecode back to Python source code using Decompyle (included.)

Requires Ruby 1.9 and Python 2.5.

Bayard Randel
Nice. Hadn't heard of unholy before.
Andrew Grimm
A: 

For python code to run the interpreter needs to be launched as a process. So system() is your best option.

For calling the python code you could use RPC or network sockets, got for the simplest thing which could possibly work.

Felix
Great, that's what I intend on doing. Don't see any reason to be fancier than using system() alone.
Eric
I don't think that's true at all: see http://docs.python.org/extending/embedding.html for documentation of embedding the Python interpreter into another application. Which, for the perverse, could be the Ruby interpreter.
Mike Woodhouse