Getting Python and Ruby to Talk to Each Other

A clueless Ruby newbie seeks help…

I have gotten Ruby’s amazing Linda tuplespace up and running which was
incredibly easy, so not using Ruby is not an option – and I have a
database (not relational, not at all standard, written in C) that I
must use a Python extension to query and capture result sets, so not
using Python is not an option.

So how can I pass a query (in the form of a text string) from rinda to
Python, and how can I pass the results (also in the form of a text
string) from Python back to rinda?

I tried opening the same socket in Python and Ruby (works in Ruby
only!) and got a “packet size” error. It’s also been suggested to me
that I use mkfifo to set up a pipe for the Python process to
communicate with the Ruby process.

Any thoughts on this? I’m obviously quite inexperienced at this, so a
sample snippet of ruby code would really help.

Thanks in advance!

Have you checked out Ruby/Python in RAA?

http://www.ruby-lang.org/en/raa-list.rhtml?name=Ruby%2FPython

I’ve never used it (although I am concurrently a Python programmer)-- but it
may be what you’re looking for.

···

On Saturday 14 September 2002 06:06 pm, Sam Hunting wrote:

A clueless Ruby newbie seeks help…

I have gotten Ruby’s amazing Linda tuplespace up and running which was
incredibly easy, so not using Ruby is not an option – and I have a
database (not relational, not at all standard, written in C) that I
must use a Python extension to query and capture result sets, so not
using Python is not an option.

So how can I pass a query (in the form of a text string) from rinda to
Python, and how can I pass the results (also in the form of a text
string) from Python back to rinda?

I tried opening the same socket in Python and Ruby (works in Ruby
only!) and got a “packet size” error. It’s also been suggested to me
that I use mkfifo to set up a pipe for the Python process to
communicate with the Ruby process.

Any thoughts on this? I’m obviously quite inexperienced at this, so a
sample snippet of ruby code would really help.

Thanks in advance!


Bruce Williams http://www.codedbliss.com
iusris/#ruby-lang bruce@codedbliss.com

In article 7c40e468.0209141347.4d338e56@posting.google.com,

···

Sam Hunting shunting@etopicality.com wrote:

A clueless Ruby newbie seeks help…

I have gotten Ruby’s amazing Linda tuplespace up and running which was
incredibly easy, so not using Ruby is not an option – and I have a
database (not relational, not at all standard, written in C) that I
must use a Python extension to query and capture result sets, so not
using Python is not an option.

Well, since the database is written in C you could write a C extention for
Ruby just as you have for Python. Perhaps you could use SWIG
(http://www.swig.org) for this? I would suggest that this would probably
be easier than having Python query your C database and pass the info to
Ruby.

Phil

“Sam Hunting” shunting@etopicality.com wrote in message
news:7c40e468.0209141347.4d338e56@posting.google.com

A clueless Ruby newbie seeks help…

I have gotten Ruby’s amazing Linda tuplespace up and running which was

So how can I pass a query (in the form of a text string) from rinda to
Python, and how can I pass the results (also in the form of a text
string) from Python back to rinda?

This problem seems a bit inversed to me.

I would consider tuplespaces to be close to the ideal cross language
interface.
So the “right” way would be to hook Python up to Rindas network protocol.
For pratical reasons this is proably not the easiest way though.

Mikkel

> So how can I pass a query (in the form of a text string) from rinda to
> Python, and how can I pass the results (also in the form of a text
> string) from Python back to rinda?
>

Have you checked out Ruby/Python in RAA?

http://www.ruby-lang.org/en/raa-list.rhtml?name=Ruby%2FPython

Yes, but I was hoping for something more lightweight. It would be better
if "just worked" to connect Ruby and Python, I think.

Sam Hunting
eTopicality, Inc.

···

---------------------------------------------------------------------------
"Turn your searching experience into a finding experience."(tm)

Topic map consulting and training: www.etopicality.com
Free open source topic map tools: www.goose-works.org

XML Topic Maps: Creating and Using Topic Maps for the Web.
Addison-Wesley, ISBN 0-201-74960-2.
---------------------------------------------------------------------------

Another option is SOAP4R and PySOAP. However, depending on your desire to get
rid of the “legacy” Python code, SWIG may be your best bet.

  • Wilkes
···

— Phil Tomson ptkwt@shell1.aracnet.com wrote:

In article 7c40e468.0209141347.4d338e56@posting.google.com,
Sam Hunting shunting@etopicality.com wrote:

A clueless Ruby newbie seeks help…

I have gotten Ruby’s amazing Linda tuplespace up and running which was
incredibly easy, so not using Ruby is not an option – and I have a
database (not relational, not at all standard, written in C) that I
must use a Python extension to query and capture result sets, so not
using Python is not an option.

Well, since the database is written in C you could write a C extention for
Ruby just as you have for Python. Perhaps you could use SWIG
(http://www.swig.org) for this? I would suggest that this would probably
be easier than having Python query your C database and pass the info to
Ruby.

Phil


Do you Yahoo!?
Yahoo! News - Today’s headlines

MikkelFJ wrote:

“Sam Hunting” shunting@etopicality.com wrote in message
news:7c40e468.0209141347.4d338e56@posting.google.com

A clueless Ruby newbie seeks help…

I have gotten Ruby’s amazing Linda tuplespace up and running which was

So how can I pass a query (in the form of a text string) from rinda to
Python, and how can I pass the results (also in the form of a text
string) from Python back to rinda?

This problem seems a bit inversed to me.

I would consider tuplespaces to be close to the ideal cross language
interface.
So the “right” way would be to hook Python up to Rindas network protocol.
For pratical reasons this is proably not the easiest way though.

The real problem is how Ruby and Python marshalls it’s objects.
Rinda uses Ruby’s marshalling format, which is not compatible with
Pythons pickle format.

Regards,

Michael

Wilkes Joiner wrote:

Another option is SOAP4R and PySOAP. However, depending on your desire to get
rid of the “legacy” Python code, SWIG may be your best bet.

You can transfer data between Python and Ruby (in both directions) in just
half a dozen lines of code, by using xmlrpc4r and Python’s xmlrpclib.
An example of this can be found in Ruby Developer’s Guide, page 279.

Regards,

Michael