擅长:python、mysql、java
<p><a href="https://pypi.python.org/pypi/ruamel.yaml" rel="nofollow">ruamel</a>实现了一个往返加载程序和转储程序,请尝试:</p>
<pre><code>import ruamel.yaml
conf = open("results.conf", "r")
results = ruamel.yaml.load(conf, ruamel.yaml.RoundTripLoader)
conf.close()
results['nas']['mount_dirs'][0] = "haha"
with open('/home/zonion/speedio/speedio.conf', 'w') as conf:
ruamel.yaml.dump(results, conf, ruamel.yaml.RoundTripDumper)
</code></pre>