Нужно изменить значение в yaml файле файл:
singleuser:
image:
name: hub/k8s-network-tools
tag: "1.2.0"
Написал вот такой скрипт:
#!/usr/bin/env python
import yaml
import argparse
parser = argparse.ArgumentParser(description='Скрипт')
parser.add_argument('key', type=str, help='key')
parser.add_argument('value', type=str, help='value')
args = parser.parse_args()
with open("values.yaml") as f:
try:
list_doc = yaml.load(f)
for arr in list_doc:
arr[args.key] = args.value
with open("values.yaml", "w") as f:
yaml.dump(list_doc, f)
except yaml.YAMLError as exc:
print(exc)
Получаю ошибку:
user@myPC test % python change_values.py "singleuser.image.tag" "1.2.1"
change_values.py:13: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
list_doc = yaml.load(f)
Traceback (most recent call last):
File "change_values.py", line 16, in <module>
arr[args.key] = args.value
TypeError: 'str' object does not support item assignment
user@myPC test %
Подскажите что ни так тут, или как это правильно делается