Calling Python from Ruby

后端 未结 6 2021
旧巷少年郎
旧巷少年郎 2020-12-24 02:11

I have a compiled Python library and API docs that I would like to use from Ruby.

Is it possible to load a Python library, instantiate a class defined in it and call

6条回答
  •  死守一世寂寞
    2020-12-24 02:45

    It sounds like you would want to use something like Apache Thrift which allows either your python or your ruby code to be a server/client and call each other. http://thrift.apache.org/

    You can instantiate your objects in ruby and or in python based on your thrift definition. This is an example from the thrift website.

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

    Basically your ruby or python will be able to call store() and retrieve() and create UserProfile objects etc.

提交回复
热议问题