python - ImportError using imp.find_module from subdirectory -


i have project:

main |---src.py |---frame_select.py |-----shellsdir       |---script_select.py       |------scriptsdir              |---test.py 

main has script passes arguments frame_select.py looks inside shelldir appropriate script based on argument passed. returns , using:

import imp, sys  sys.path.insert(0, '/path/to/shellsdir/')  def module_import(mod_name):    fp, p, d = imp.find_module(mod_name)    py_mod = imp.load_module(mod_name,                             fp,                             p,                             d)  def pick(value, window):    if value == 'name_passed':       c_mod = module_import('specific_name')       c_mod.populate(window) 

there 16 scripts in shellsdir picks based on passed argument script load while looking in shellsdir. within shellsdir directory called scriptsdir , file script_selector. file looks this:

import imp, sys  sys.path.insert(0, '/path/to/scriptsdir/')  def module_import(mod_name):    fp, p, d = imp.find_module(mod_name)    py_mod = imp.load_module(mod_name,                             fp,                             p,                             d) 

essentially reusing code, pointing @ scriptsdir program pass argument module_import() function. however, not getting importerror: no module named 'name_passed'.

i've done print sys.path , /path/to/shellsdir/ , /path/to/scriptsdir both there. module name matches, not sure why error.

for frame_select.py: updated relative path src.py file.

import imp, sys  sys.path.insert(0, './shellsdir')  def module_import(mod_name):    fp, p, d = imp.find_module(mod_name)    py_mod = imp.load_module(mod_name,                             fp,                             p,                             d)  def pick(value, window):    if value == 'name_passed':       c_mod = module_import('specific_name')       c_mod.populate(window) 

for script_select.py: updated relative path src.py file.

import imp, sys  sys.path.insert(0, './shellsdir/scriptsdir/')  def module_import(mod_name):    fp, p, d = imp.find_module(mod_name)    py_mod = imp.load_module(mod_name,                             fp,                             p,                             d) 

it may worth noting ../scriptsdir/ not work. however, had figured out earlier didn't think worked due long import time. forgot had 20 modules (for testing purpose) in test.py file , that's caused delay.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -