-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optionally allow keypath_separator
in input dict keys (unflatten
).
#367
Comments
@brynpickering thanks for reporting this issue. Correct me if I'm wrong, this is a problem of the |
Also instatiation. I want The second part of my issue is more of a bug based on the existing expected functionality, but is in the correct direction for the feature I would like 😅 |
@brynpickering with d79336d the behaviour of the So, with this fix, this issue becomes a feature request instead of a bug report (correct me if I'm wrong). |
Yes, that's correct. |
@brynpickering I thought about this as feature, surely it can't be the default behaviour, because it would be "invisibly backward incompatible" when using this library with existing dicts containing the For achieving what you need, you can simply use the Writed = benedict()
# ...
f = d.flatten(separator="__")
f.to_yaml(filepath="my-dict.yml") Readf = benedict.from_yaml("my-dict.yml")
d = f.unflatten(separator="__") |
I had a look at
It's not particularly pretty and potentially involves creating the same representation of data in memory three times (I haven't looked into exactly what goes on under the hood with the data when calling You're right that it would be silently backward incompatible, but it seems more intuitive to me that defining the keypath separator on loading data is equivalent to telling benedict that any keys using that separator are meant to be separated. Perhaps a flag could be added whenever |
keypath_separator
on input dicts (unflatting those keypaths).
keypath_separator
on input dicts (unflatting those keypaths).keypath_separator
in input dict keys (unflatted
).
keypath_separator
in input dict keys (unflatted
).keypath_separator
in input dict keys (unflatten
).
We're loading in YAML files where we allow the dot notation in place of nested keys. Therefore, the
keypath_separator
is.
and I'd like that to remain the separator in the resultingbenedict
.Therefore:
foo.bar: 1
should be loaded in as{'foo': {'bar': 1}}
and then be accessible asmy_dict["foo.bar"]
andmy_dict["foo"]["bar"]
.Interestingly, in the currently
benedict
implementation, I can make this happen for top-level keys containing the keypath separator, as follows:But I get the (expected) error in these two cases:
python-benedict
version: 0.33.1Upvote & Fund
The text was updated successfully, but these errors were encountered: