Search and Replace of string in a yaml file

Test Bot onlinejudge95 at gmail.com
Wed Mar 27 05:42:48 EDT 2019


Assuming you are asking about the logic at the uber level.

You can try handling yaml file with pyyaml. It is a 3rd party package which
has a good support for I/O related to yaml files.

After you are able to read the data from the file, you need to apply your
business logic to it. And log all the erroneous matches.

For example

import yaml

with open(path/to/yaml/file, "r") as fp:
    yaml_data = yaml.safe_load(fp)


On Sat, Mar 23, 2019, 5:33 PM Pradeep Patra <smilesonisamal at gmail.com>
wrote:

> Hi all,
>
> I have several yaml files in a directory around 100s. I have some values
> and my script should search a string(reading from the JSON file)  from the
> series of yaml files and run some validation like the key of the file that
> is updated  in the yaml file and run some basic validation tests like data
> integrity of the replaced string with the source string read from JSON. Can
> anyone suggest some reliable and efficient method to achieve this and
> appreciate some examples for the same?
>
> Regards
> Pradeep
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list