In my main module, I have the following:
function_dictionary = utilities.load_modules()
Which calls this:
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
Now that the modules have been loaded, my main module calls this:
recovery.start("recovery.txt")
Which in turn calls this from the recovery module:
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()
I want eval to execute:
user_operations.remove_user(URL,acc_531,user_29080,"id",headers)
Where user_operations
is the name of one of the imported modules and remove_user
is a function within it.
However, I get the following error:
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
Is this because the imported modules are not within the scope of the recovery module? If so, does anybody know how to make it so they are?
Thanks
P.s I am aware Eval is evil etc etc