pubyRuby 的 Python 接口
puby 是 Ruby 解释器的 Python 接口。
示例代码
解析 HTML
# python # # ruby from puby import Object as rb # rb.require("nokogiri") # require "nokogiri" rb.require("open-uri") # require "open-uri" url = "http://www.google.com/search?q=foo" # url = "http://www.google.com/search?q=foo" doc = rb.Nokogiri.HTML.parse(rb.open(url)) # doc = Nokogiri::HTML.parse(open(url)) for link in doc.css("h3.r a"): # doc.css("h3.r a").each do |link| print link.content() # puts link.content # end执行 JavaScript:
from puby import Object as rb # rb.require('v8') # require "v8" ctx = rb.V8.Context.new() # ctx = V8::Context.new print ctx.eval("'Xzibit ' + 7 * 6") # puts ctx.eval "'Xzibit ' + 7 * 6"运行 Web 服务器:
from puby import Object as rb # rb.require("rack") # require "rack" # def application(env): # def application(env) return [200, # [200, {"Content-Type": "text/html"}, # {"Content-Type" => "text/html"}, ["Hello Puby!"]] # ["Hello Puby!"]] # end rb.Rack.Handler.Thin.run(application) # Rack::Handler::Thin.run method(:application)回调示例:
from puby import Object as rb, RbCallback rb.eval(""" class TestObj def save_callback cb @cb = cb end def call_callback x @cb.call(x) end end """) obj = rb.TestObj.new() def callback(x): return x+1 callback_rb = RbCallback(callback) obj.save_callback(callback_rb) print obj.call_callback(5)
评论
psycopgPostgreSQL的Python接口
psycopg是一个PostgreSQL数据库的Python语言的接口。psycopgisaPostgreSQLdatabaseadapterforthePythonprogramminglangua
psycopgPostgreSQL的Python接口
0
pymormMongoDB的Python接口
pymorm是一个基于ORM框架的pymongo接口。代码示例:from pymorm import MongoObject, MongoObjectMetafrom pymongo import M
pymormMongoDB的Python接口
0
PyFileMakerFileMaker 的 Python 接口
PyFileMaker 是 FileMaker 的 Python 接口。FileMaker Pro是
PyFileMakerFileMaker 的 Python 接口
0
DulwichGit 的 Python 接口
Dulwich是一个Git文件格式和协议的纯Python实现,支持读取资源库内容、索引以及通过Git网络协议进行数据的读写。支持本地和远程Git资料库。Dulwich不依赖于任何Git相关内容。相当于
DulwichGit 的 Python 接口
0
PyMongoMongoDB的Python接口
PyMongo是MongoDB的Python接口开发包。示例代码:创建Connection时,指定host及port参数>>>importpymongo>>>con
PyMongoMongoDB的Python接口
0
PystAsterisk的Python接口
Pyst包含一种用来对Asterisk编程的Python接口和库,支持AGI,AMI,可解析Asterisk配置文件,包括调试工具。
PystAsterisk的Python接口
0