Dynamic creation of named object
At some places I don't want to read objects from the config, to reduce verbosity.
(we have to deal with a lot of intermediate virtual object, i don't want BCU people wast there time to write such config and update it)
I expect such object to be reachable by name.
Is there actually a way to register such object?
Here is my solution. Which use private stuffs static.get_config()._name2instance[name] = self
So the object is reachable using static.get_config()..get(name)
class AutoProjection(BeaconObject):
def __init__(self, tomoconfig):
assert tomoconfig is not None
name = f"{tomoconfig.name}.auto_projection"
super().__init__(config={}, name=name)
# As this instance is generated and not read from yml, we have to register it's name
static.get_config()._name2instance[name] = self
So, is there actually a better way?
Edited by Valentin Valls