Call python code from Ruby -
i want run python code ruby. using gem. ruby code:
require "rubypython" rubypython.start fileinput=rubypython.import("fileinput") rubypython.stop
i error : rubypython warning: undefining `object_id' may cause serious problems
ruby code:
require "rubypython" rubypython.start fileinput=rubypython.import("fileinput") name='' name2="" r=0 i=0 open_file=fileinput.input("lala") output=open("lalal","w") line in open_file: keys=line.split() length=(len(keys)) if length==3: if (keys[0]!=name , 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
i error:
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))
seems gem not working. can problem?
thanks in advance
rubypython allows use python objects within ruby, code has valid ruby code (it exposes wrapper objects work python objects in background). translate code ruby equivalent using tool, @ point, might rewrite in ruby, cleaner, more readable, , more efficient.
there no way, far know, insert python code ruby script , have run. such project pretty out-there , unlikely approaching efficient.
either rewrite python code ruby code, or make python code stand-alone script can call python interpreter run ruby. naturally option if code doesn't need ton of interaction rest of application, communication have happen using stdin/stdout.
Comments
Post a Comment