python/ruby question..

Matimus mccredie at gmail.com
Thu Jun 19 19:00:13 EDT 2008


On Jun 18, 8:33 pm, "bruce" <bedoug... at earthlink.net> wrote:
> hi...
>
> can someone point me to where/how i would go about calling a ruby app from a
> python app, and having the python app being able to get a returned value
> from the ruby script.
>
> something like
>
> test.py
>  a = os.exec(testruby.rb)
>
> testruby.py
>  foo = 9
>  return foo
>
> i know this doesn't work... but i've been searching for hours on this with
> no luck.... (and yeah, i'm relatively new to both ruby/python!!)
>
> thanks

Both Ruby and Python appear to support XMLRPC. I haven't used XMLRPC
in Ruby, but in general you create a server and expose some functions.
On the client end (Python) you would do something like this (assuming
you are serving on port 8050):

import xmlrpclib

rubyserver = xmlrpclib.Server("http://localhost:8050")
x = rubyserver.foo(1,2,3)

where 'foo' is a function served by the ruby server and x is its
return value.

some links:

http://www.ruby-doc.org/stdlib/libdoc/xmlrpc/rdoc/index.html

Good python server and client examples on this page:

http://docs.python.org/lib/simple-xmlrpc-servers.html

I can't be of much help for ruby, and that link doesn't seem to help
much other than to say 1. it exists and 2. its easy.

Matt



More information about the Python-list mailing list