I have some functions that process the parameter, like :
def createDataModel(objectModel):
......
def createLayoutModel(objectModel):
......
def createWidgetModel(objectModel):
......
I have some xml as input files, with a specific root tag name, like ( dataModel, layout, page) then I convert them to a object model. I have a map that determines which function should process the object model
xsdPathsMap = {
"dataModel": createDataModelFromXml,
"layout": createLayoutModel,
"page": createWidgetModelFromXml
}
Then I create object models from xml and assign them the function that should process them,
result = xsdPathsMap[xmlRootName]
# a is objectified xml
a.modelerFunction = result
when I want to pass the object to its closure method I got this exception:
a.modelerFunction(a)
TypeError: object is not callable
what is the problem?
and this is my Traceback :
Traceback (most recent call last):
File "model/xmlTranporter.py", line 204, in <module>
a = main("main/schema")
File "model/xmlTranporter.py", line 200, in main
a(obj)
TypeError: 'lxml.objectify.StringElement' object is not callable
I’m not sure why you’re doing this assignment:
Either add the modeler functions to the class of
aand just call it as a method:Or just pass a to the modeling function:
However, this assumes that your modeling functions that you’re retrieving from the map are in fact functions and not classes.
If you want to define classes that are callable that’s of course fine but you need to define the
__call__protocol method: