I am trying to learn Python,
import sys
sys.path.append(path + 'script/')
scriptLIST = ['createDummy','importController','matchPosition']
for obj in scriptList:
from importlib import import_module
i = import_module(obj)
reload(i)
i.importGroup()
I have some scripts, and I want to call them with a script, but this script give me an error in 'reload(i)', I need this reload to update those scripts. Could you please help me with this little script.
Here's a few things you ought to consider:
sys.path.append(path + 'script/')
doesn't look right : you haven't provided us what we'd expect to see in path
, but unless path
is a complete path string ending in a slash it won't work. Print out sys.path
and see what you're actually adding. scriptLIST
and scriptList
are not the same -- Python variables are case sensitive. You might have a leftover variable from an earlier run messing up your results. from importlib import import_module
outside the loop. You almost never want to import inside a loop import_module(obj)
so you know if you've gotten what you need. Since you're using strings it would be easy for a typo to mess up your operations.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.