擅长:python、mysql、java
<p>首先,修复详细列表,<strong>不要使用'list'作为变量名,因为它是python中保留的关键字,声明列表的括号应该是[],而不是{},如下所示:
<strong>详细信息.py:</strong></p>
<pre><code>verbe_list = [
{
"FIELD1": "\"A\"",
"FIELD2": "\"B\"",
"FIELD3": "\"C\"",
"FIELD4": "\"D\"",
"FIELD5": ""
}...
]
</code></pre>
<p>如果你想使用详细信息.py在另一个python脚本中,可以如下导入。嵌套for循环将打印verbe\ u列表中的所有键和值。你知道吗</p>
<p><strong>主.py:</strong></p>
<pre><code>from verbes import verbe_list
for item in verbe_list:
for k, v in item.items():
print(k, v)
</code></pre>
<p><strong>更新:</strong>
这将为您提供“FIELD1”的所有值。你知道吗</p>
<pre><code>first_object_of_all_dict = [item['FIELD1'] for item in verbe_list]
</code></pre>
<p>结果:</p>
<pre><code>['"A"', '"Base verbale (to...)"', '"arise"']
</code></pre>
<p>如果要在verbe\ u列表的第一个dict中输入'FIELD1'的值:</p>
<pre><code>first_object_of_first_dict = verbe_list[0]['FIELD1']
</code></pre>
<p>结果:</p>
<pre><code>"A"
</code></pre>