擅长:python、mysql、java
<p>使用PyYaml,可以执行以下操作:</p>
<pre><code>with open("file.yaml", 'r') as handle:
for event in yaml.parse(handle):
# handle the event here
</code></pre>
<p>这将逐个事件地处理YAML文件,而不是将其全部加载到数据结构中。当然,您现在需要从事件流中手动解析结构,但这允许您进一步处理部分数据。在</p>
<p>您可以查看PyYaml的<a href="https://github.com/yaml/pyyaml/blob/master/lib3/yaml/composer.py#L29" rel="nofollow noreferrer">Composer implementation</a>,看看它是如何从事件中构造Python对象的,以及它期望从事件流中得到什么结构。在</p>