Weremole79
Weremole79

Reputation: 55

Python and Ruby interpreter

I read in books that you are capable of incorporating scripts of other languages into Python. Is it possible to take variables from a ruby script, pass them to a python function, and then return the output back to Ruby? If so, how? Every answer will be greatly appreciated!

Upvotes: 3

Views: 332

Answers (1)

mjgpy3
mjgpy3

Reputation: 8947

Here are a few ways you could do it. Note that none of these has exceptionally high performance:

  • It might be overkill, but I have used socket programming before to set up a client-server relationship between Python and Ruby. At the very least this approach feels cool.

  • You could write and read from a common file. But then you have to worry about concurrency issues.

  • backticks can be used to send something to a Python module. In the Python module you wouold then use argv to process the sent data and then return back some result to the Ruby code.

For further information I would suggest looking at another similar StackOverflow question.

Upvotes: 4

Related Questions