I want to call python classes dynamically,
These are the classes that I want to call
class AutosoukModelMakeFuzzyComparisonModule:
def __init__(self,configurationLoader=None, moduleConfigurationFile=None, settings=None):
pass
and
class DefaultFuzzyComparisonModule:
def __init__(self,configurationLoader, moduleConfigurationFile, settings = None):
pass
and these too classes located in fuzzymodules folder
and I call them from ** FuzzyComparisonPipeline.py** which is in the same directory as fuzzymodules like this:
for module in FuzzyComparisonPipeline.fuzzyModules:
name = module['name']
configurationLoader = module['configurationLoader']
moduleConfigurationFile = module['moduleConfigurationFile']
settings = module['settings']
module_to_import = __import__('fuzzymodules.'+name)
instanceOfModule = getattr(module_to_import, name).__init__(configurationLoader, moduleConfigurationFile, settings)
#instanceOfModule(configurationLoader, moduleConfigurationFile, settings)
return item
I got this error:
Traceback (most recent call last):
File "path to my FuzzyComparisonPipeline.py", line 9, in process_item
instanceOfModule = getattr(module_to_import, name).__init__(configurationLoader, moduleConfigurationFile, settings)
TypeError: module.__init__() takes at most 2 arguments (3 given)
and my question is how the init() takes 2 arguments, as you see, in both classes the init takes three arguments
Could you help please
i can't give you the whole code, because it is so complicated, everything else is working fine, i am sure of that, my problem is in calling that function.
the values of the for loop coming from this xml
<FuzzyComparison>
<Modules>
<Module>
<name>AutosoukModelMakeFuzzyComparisonModule</name>
<configurationLoader>DefaultLoader</configurationLoader>
<configurationFile>MakesModels.conf</configurationFile>
<settings></settings>
</Module>
<Module>
<name>DefaultFuzzyComparisonModule</name>
<configurationLoader>DefaultLoader</configurationLoader>
<configurationFile>Buildings.conf</configurationFile>
<settings>
<attribute>building</attribute>
<second>2222duxk fuck fuck</second>
</settings>
</Module>
</Modules>
</FuzzyComparison>
__init__directly, you'd call the object itself (just remove the.__init__part). But clearly you are not getting the right code here as you are trying to instantiate that doesn't take 3 arguments. If you gave us an actual traceback we might be able to be of more help.namein your example? Which.pyfile does it lie in, what is the directory structure for that.pyfile? Also, 1.__init__()in your examples take 4 arguments (the first being the object itself) . 2.__init__()is not used for object creation, its used for object initialization , but seems like you want to use it for object creation (but it should not be used like that) .