I have the following code in which the function is not being called and an error is being returned. Following is the code -
def deleteExistingBackupFiles(step):
try:
for setting in step.Setting:
key = setting['key']
value = setting['value']
configTable.update({key: value})
if os.path.isfile(value):
os.remove(value)
elif os.path.isdir(value):
shutil.rmtree(value)
except:
report.update({"DeleteExistingBackup":"There was a problem while trying to delete old files."})
def main():
scriptPath = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
configFilePath = os.path.abspath(os.path.realpath(scriptPath + '\config.xml'))
parsedXML = ET.parse(configFilePath)
#try:
for step in parsedXML.iter('Step'):
for setting in step.iter('Setting'):
print setting.attrib.get('key')
print setting.attrib.get('value')
configTable.update({setting.attrib.get('key'): setting.attrib.get('value')})
for step in tqdm(parsedXML.iter('Step'), desc='Wordpress Backup Restoration : '):
methodName = step.attrib.get('methodname')
result = methodName
result(step)
While trying to execute the last statement, I am getting the following error -
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2017.1.2\helpers\pydev\pydevd.py", line 1585, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files\JetBrains\PyCharm 2017.1.2\helpers\pydev\pydevd.py", line 1015, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:/Users/Pranav/PycharmProjects/DevEnv/Blog.py", line 119, in <module>
main()
File "C:/Users/Pranav/PycharmProjects/DevEnv/Blog.py", line 106, in main
result(step)
TypeError: 'str' object is not callable
The methodName contains DeleteExistingBackupFiles yet it is still not working. Any idea what is going wrong?
Although when I try to execute the following code, it works fine -
def sampleFunc(arg):
print('you called sampleFunc({})'.format(arg))
result = (sampleFunc)
result("Hello World!")
Have a nice day!
result = sampleFuncandresult = "sampleFunc"result, you're not assigning the function. You can't call a string.dictto look up functions by a string.