Skip to content
Advertisement

Way to delete yaml keys in the form “a.b.c.e”?

I have yaml keys in the form “a.b.c.d” but my yaml file is in the format:

JavaScript

I want to delete “a.b.c.e” here and I have around 300 rows of yaml keys in similar format any idea on how to delete the keys?

I know about the del function in ruamel.yaml if it will be possible integrate.

Like Lets say I delete “a.b.c.e”

the desired output:

JavaScript

I know there is a problem with syntax. The actual yaml file has many more lines.

Advertisement

Answer

Yes but after splitting it I will get a list [“a”,”b”,”c”,”e”] and the format for key deletion would be del d[“a”][“b”][“c”][“e”] I do not know how to convert the list into that statement because not all the keys are of same length some are of form “a.b.c.d.e.f”.That is the problem I am facing.

something like this?

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement