用dict中的重复键构造数据结构(但不能使用数组)

2024-04-26 23:11:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Suds为以下数据结构发送SOAP请求

<WriteRequest>
  <ClassName>Fifth_Grade</ClassName>
  <UpdateStudent>
    <StudentName>Andrew</StudentName>
    <StudentWeight>60</StudentWeight>
    <StudentName>Mike</StudentName>
    <StudentWeight>54</StudentWeight>
    <StudentName>Emma</StudentName>
    <StudentWeight>71</StudentWeight>
  </UpdateField>
</WriteRequest>

当我为updatestudent创建dict时,StudentName和StudentWeight的键值在每次迭代赋值时都会被覆盖。你知道吗

如果我使用数组,提交的数据结构就会变成这样一种不受欢迎的格式

<UpdateStudent>
        <StudentName>Andrew</StudentName>
        <StudentWeight>60</StudentWeight>
</UpdateStudent>
<UpdateStudent>
       <StudentName>Mike</StudentName>
       <StudentWeight>54</StudentWeight>
</UpdateStudent>

关于如何最好地用python表示第一个数据结构的想法。你知道吗

谢谢你!!你知道吗


Tags: 数据结构soapsudsmikegradeandrewemmaclassname