Menu ▾ ▴

#406 get file name from data ruamel data struxture

closed
nobody
None
minor
proposal
2021-11-07
2021-11-07
arne
No

Is it possible to retrieve the file name from the data structure of a parsed yaml file?

In my application I am parsing multiple yaml files.
To the detailed plausibility checking is happening somewhere deep down in the program structure.
At that points I am using the data[key]. lc. to get point to the collection where e.g. an entire is missing, where I am informing the user.
It would be very helpfull to get the filename of the original yaml form the ruamel data object to display it here

Discussion

  • Anthon van der Neut

    • summary: get file name from data rumel data struxture --> get file name from data ruamel data struxture
     
  • Anthon van der Neut

    This is not a bug report, so you should post this question on stackoverflow as per the help text.

    The data structure contained doesn't include the filename. There is of course no obligation to load from a file in the first place.

    It is trivial to graft the filename on the root-level object as an attribute after the data is loaded and returned. Alternatively you could use ruamel.yaml.base, which keeps the filename in the ._path attribute where you can access the .data attribute for the root of the content (loaded only when accessed).

     
  • Anthon van der Neut

    • status: open --> closed
    • discussion: enabled --> disabled