在我的主要模块中,我有以下内容:
function_dictionary = utilities.load_modules()
这称之为:
def load_modules():
function_dictionary = {}
print "\nLoading modules..."
for path, subdirs, files in os.walk("modules"):
for name in files:
if name.lower().endswith('.py') and name != "__init__.py":
print "Importing " + os.path.join(path, name) + "..."
try:
module = imp.load_source('utilities',os.path.join(path, name))
function_dictionary = dict(function_dictionary.items() + module.function_dictionary.items())
except Exception, e:
print( "Import Error: %s" % str(e) )
return function_dictionary
现在模块已加载,我的主模块调用它:
recovery.start("recovery.txt")
反过来又从恢复模块中调用它:
if recovery:
for command in content:
print ("\n"+command)
result = eval(command)
if not result:
continue_recovery = utilities.query_yes_no("Warning: Previous recovery command was failure, continue recovery?")
if not continue_recovery:
break
end()
我想要执行eval:
user_operations.remove_user(URL,acc_531,user_29080,"id",headers)
其中user_operations
是其中一个导入模块的名称,remove_user
是其中的一个函数。
但是,我收到以下错误:
Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensio
ns\Microsoft\Python Tools for Visual Studio\2.0\visualstudio_py_util.py", line 7
6, in exec_file
exec(code_obj, global_variables)
File "C:\Users\mryan\Documents\Code\pcli_front.py", line
67, in <module>
recovery.start_recovery(recovery_file, auto_recovery, headers)
File "C:\Users\mryan\Documents\Code\recovery.py", line 1
21, in start_recovery
result = eval(command)
File "<string>", line 1, in <module>
NameError: name 'user_operations' is not defined
这是因为导入的模块不在恢复模块的范围内吗?如果是这样,有人知道如何制作它们吗?
由于
P.s我知道Eval是邪恶的等等