halostatue-archive / rubypython

An in-process between Ruby and Python 2.
Other
254 stars 47 forks source link

Import local python modules? #14

Open halostatue opened 7 years ago

halostatue commented 7 years ago

Not sure if it is impossible but is RubyPython able to import a local python module (i.e. test.py within the local directory)? All attempts I have tried yield a ImportError: No module named test

RutujaWanjari commented 7 years ago

I am also facing same issue

peter-wangxu commented 7 years ago

Hi @RutujaWanjari

Sure, see example here:

~/temp/ruby$ cat test_dict.rb
require "rubypython"

RubyPython.start
sys = RubyPython.import("sys")
sys.path.append('.')
my = RubyPython.import("test_dict")
r = my.test_dict
if r == nil
    puts("Nil")
else
    puts("FAILED")
end

puts(r.to_a.length)
#r.to_enum.each do |key|
#    puts(key)
#    puts(r[key])
#end

Note, I had a test_dict.py file in the same folder.