Мой код и структура данных, которая приводит к выводу ниже, выглядит следующим образом:
Actions = set()
# loop through and obtain a list of files and commands
for item in d['server']:
Actions.add('{action}'.format(**item))
print(Actions)
commands = list(Actions)
commands = list(Actions)
Вывод:
Actions = {"{'command1': ['uptime'], 'path': ['/var/log/syslog']}", "{'command1': ['df -h'], 'path': ['/var/log/auth.log']}"}
Мне нужно извлечь команды и пути отдельно и что-то вродеэто не работает
print(commands[0]['command1'])
Traceback (most recent call last):
Файл "read_shell_yaml.py", строка 46, в печатном виде (команды [0] ['command1']) TypeError: строковые индексы должны быть целыми числами