代码之家  ›  专栏  ›  技术社区  ›  Bryan Ash

从Ruby调用Python

  •  28
  • Bryan Ash  · 技术社区  · 14 年前

    5 回复  |  直到 14 年前
        1
  •  14
  •   kindall    14 年前

    This article 给出了一些从Python运行Ruby代码的技术,这些技术应该也适用于相反的方向(如XML-RPC或管道),以及从Ruby运行Python代码的具体技术。特别地 rubypython Ruby/Python

        2
  •  5
  •   Martin    12 年前

    听起来您可能想使用类似Apache Thrift的东西,它允许python或ruby代码作为服务器/客户机并相互调用。 http://thrift.apache.org/

    你可以在ruby和/或python中根据你的节俭定义实例化你的对象。这是节俭网站的一个例子。

    struct UserProfile {
        1: i32 uid,
        2: string name,
        3: string blurb
      }
      service UserStorage {
        void store(1: UserProfile user),
        UserProfile retrieve(1: i32 uid)
      }
    

    基本上你的ruby或者python可以调用 store() retrieve() UserProfile 物体等。

        3
  •  4
  •   postfuturist    12 年前

    这个小小的图书馆让你非常容易做到: https://github.com/steeve/rupy

        4
  •  2
  •   Joshua    14 年前

    如果你真的找不到一个等价的Ruby库(或者你想利用它在Python上的巨大投资),可以考虑使用一个队列(比如RabbitMQ)来实现消息传递设计。然后您可以保留Python位Python和Ruby位Ruby,而不尝试维护Frankenstein构建环境。

        5
  •  1
  •   HappyFace    5 年前

    https://github.com/mrkn/pycall.rb

    下面是一个调用Python的数学.sin函数并将其与数学.sin在Ruby中:

    require 'pycall/import'
    include PyCall::Import
    pyimport :math
    math.sin(math.pi / 4) - Math.sin(Math::PI / 4)   # => 0.0
    

        6
  •  0
  •   AShelly    14 年前