我想從ruby運行python代碼。 我using this gem. Ruby代碼:從Ruby調用python代碼
require "rubypython"
RubyPython.start
fileinput=RubyPython.import("fileinput")
RubyPython.stop
我得到的錯誤: rubypython警告:取消定義`OBJECT_ID」可能會導致嚴重的問題
Ruby代碼:
require "rubypython"
RubyPython.start
fileinput=RubyPython.import("fileinput")
name=''
name2=""
r=0
i=0
open_file=fileinput.input("lala")
output=open("lalal","w")
for line in open_file:
keys=line.split()
length=(len(keys))
if length==3:
if (keys[0]!=name and i!=0):
output.write("%s\t%s\t%s\n"%(name,name2,r))
name=keys[0]
name2=keys[1]
r=float(keys[2])
output.write("%s\t%s\t%s\n"%(name,name2,r))
output.close()
RubyPython.stop
我得到的錯誤:
unique.rb:12: syntax error, unexpected ':', expecting keyword_do_cond or ';' or '\n'
unique.rb:15: syntax error, unexpected ':', expecting keyword_then or ';' or '\n'
if length==3:
^
unique.rb:17: syntax error, unexpected ':', expecting keyword_then or ';' or '\n'
unique.rb:18: syntax error, unexpected ')', expecting '='
output.write("%s\t%s\t%s\n"%(name,name2,r))
似乎寶石不起作用。可能是什麼問題?
在此先感謝
據我所知,這允許您在Ruby中使用Python對象,但不能將Python代碼插入Ruby代碼的中間。 –
什麼可以讓我在我的Ruby代碼中使用Python代碼? – Tonja
據我所知,沒有這樣的項目。可以用Ruby重寫你的代碼,也可以將它作爲Ruby腳本中的獨立腳本來調用。 –