-
Hi! I would like to access the parent key name of an attribute, probably via a resolver, would that be possible?
The reason is that I would like to pass the name of a parent to its children, e.g., a named storage that takes the name of the task that uses that storage system. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @jzazo! Custom resolvers can take a special from omegaconf import OmegaConf
def parent_name_impl(_parent_) -> str:
return _parent_._key()
OmegaConf.register_new_resolver("parent_name", parent_name_impl)
cfg = OmegaConf.create({"john": {"height": 180, "weight": 75, "player": "${parent_name:}"}})
assert cfg.john.player == "john" The standard caveats for undocumented/internal methods apply... |
Beta Was this translation helpful? Give feedback.
Hi @jzazo!
I hope you don't mind using undocumented/internal OmegaConf methods, because I don't think this can be achieved with OmegaConf's public API.
Custom resolvers can take a special
_parent_
argument (this part is documented, just before the "Built in Resolvers" section). This, in combination with the undocumented_key()
method, will be enough to do the job:The standard caveats for undocumented/…