In javascript, one can store a function class with function parameters inside an object like so:
const myFunctionClass = function(){
this.propertyFunction = function myFunc(){
console.log('hi')
}
}
const initFunctionClass = new myFunctionClass()
const obj = {}
obj["myFunctionClass"] = initFunctionClass
console.log(obj)
/* Output
{
myFunctionClass: myFunctionClass { propertyFunction: [Function: myFunc] }
}
*/
The javascript code allows to pass an initiated class around and use its functions by other modules when imported.
Is there a similar pattern in python? If so, what is the pattern? If not, could someone help clarify how I should be thinking about this in python (maybe I'm missing something obvious), perhaps with some code examples?
import os
from os import walk
class Core:
def load_adapters(self, path):
api_adapters = {}
for folder in os.scandir(path):
api_adapter = folder.name
file = next(walk(path + '/' + folder.name), (None, None, []))[2] # [] if no file
# I want to import each found file, which will contain a class,
# then initialize the classes and validate them with unit testing
from api_adapters[api_adapter][file] import api_adapter # this code relates to the question
return api_adapters