'Call static method from string given class
I have a JSON that user can modify outside my code. In that, I have full class name like:
models.InputLoader.InputLoader
When I load it in code, I get this a string representation.
I want to call static method unseralize to which I pass another datum from JSON via dictionary.
InputLoader:
@staticmethod
def unserialize(d: Dict) -> InputLoader:
return InputLoader(d["x"])
def __init__(self, x):
self.x = x
In JSON:
{
"class": "models.InputLoader.InputLoader"
"x": 45
}
How can I do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
