擅长:python、mysql、java
<p>你确定yaml是正确的吗?{<cd1>}应该是一个{<cd2>};目前,键将是<code>general</code>,其值为<code>hartexToken = 'the bot token'</code>:</p>
<p>(您需要安装pyyaml)</p>
<pre><code>pip install pyyaml
>>> import yaml
>>> with open('demo.yaml','r') as f:
... datamap = yaml.safe_load(f)
...
>>> datamap
{'general': "hartexToken = 'the bot token'"}
</code></pre>
<p>如果yaml确实如您所说,那么您当然可以<code>split</code>获取“bot令牌”的值</p>
<pre><code>>>> datamap['general'].split('=')[1]
" 'the bot token'"
</code></pre>