0
我想從蟒蛇值,把它們放在YAML:如何讓Python更新YAML的變量?
import ruamel.yaml
file_name = 'input.yml'
from ruamel.yaml.util import load_yaml_guess_indent
config, ind, bsi = load_yaml_guess_indent(open(file_name))
instances = config['instances']
print instances
instances['hostname'] = raw_input('What is the host name>>')
instances['syslog'] = raw_input ('what is the Syslog ip address>>')
instances['prefix'] = raw_input('What is the first prefix>>')
instances['prefix'] = raw_input ('what is the second address>>')
input.yml
:
---
instances:
hostname: <name> # update with IP
syslog: <ip> # update with user name
interfaces:
- name: GigabitEthernet0/0
prefix: <first prefix>
- name: GigabitEthernet0/1
prefix: <second prefix>
主機和系統日誌部分工作,但我不能讓前綴工作。
是的,它的工作完美。非常感謝。 – NANIS
@NANIS下一次,如果遇到問題,請提供您正在獲取的錯誤文本。特別是當你不能提供完整的程序,這將不可能爲其他人產生錯誤。 – Anthon