Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Code:
- import yaml
- import os
- import re
- with open("test.yaml", 'r') as stream:
- try:
- loaded=stream.read()
- except yaml.YAMLError as exc:
- print(exc)
- with open("modified.yaml", 'w') as stream:
- try:
- yaml.dump(re.sub(r'anotherName: [^\n]*', 'anotherName: somethingChanged', loaded), stream)
- except yaml.YAMLError as exc:
- print(exc)
- OUTPUT:
- cat modified.yaml
- "---\nkind: test\nscope: not far\nspec:\n test1:\n options:\n - name: test.com\n\
- \ anotherName: somethingChanged\n empty: []\n groupOne: []\n \
- \ emptyList:\n firstList: []\n secondList: []"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement