-
Image I have two objects that depend on the same value, but I want to keep a good dependency injection pattern without too much of a manual coding. class A:
def __init__(today: str):
self.today = today
class B:
def __init__(today: str):
self.today = today Both of these classes have their own config files. How can I keep today consistent between these two? Does hydra provide any solution? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
See OmegaConf's variable interpolation feature. Are you using Hydra's instantiate API? If so, something like this should work: # my_config.yaml
a_instance:
_target_: my_module.A
today: ${today}
b_instance:
_target_: my_module.B
today: ${today}
today: ... The string |
Beta Was this translation helpful? Give feedback.
See OmegaConf's variable interpolation feature.
Are you using Hydra's instantiate API? If so, something like this should work:
The string
"${today}"
is a "variable interpolation". It essentially functions as a pointer to the top-level"today"
key.