I have a class to parse data from some online dictionaries, it reads info about word from json and then executes methods as json tells to. An example of json:
{
"functions": [
{
"name": "find_translations",
"properties": {
"only_first": false
}
},
{
"name": "find_synonyms",
"properties": {
"number": 5
}
],
"word": "to exuberate",
"language": "angielski",
"target_language": "polski",
"collection": "default"
}
So, I have a class with methods find_translations and find_synonyms. And __init __ is reading the json, and I want to execute functions with parameters as in json. I could do a bunch of ifs, but it isn't scalable, I guess. I could do eval(), but it is a vulnerability. What do I do? Can I create something like a dictionary with functions?
EDIT:
Here's my class (simplified):
class Parser:
def __init__(self, path):
...
# reads data from json
...
# my problem: I need to launch methods from this class
# that were mentioned in json. In case from example, I'd launch
self.find_translations(self)
self.find_synonyms(self)
# it is an example, so without parameters
def find_translations(self):
# do something
def find_synonyms(self):
# do something
def find_usage(self):
# do something