Parsing Suds SOAP complex data type into Python dict

前端 未结 6 1848
生来不讨喜
生来不讨喜 2020-12-31 23:24

I have some data coming from a SOAP API using Suds which I need to parse in my Python script. Before I go off and write a parser (ther

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-31 23:50

    The right answer, as is often the case, is in the docs. The bits in (brackets) are objects which can contain other objects or types.

    In this case we have an ArrayOfBalance object which contains a list of Balance types, each of which has the attributes of Amount and Currency.

    These can all be referred to using . notation so the following one-liner does the trick.

    balance = {item.Currency: item.Amount for item in response.Balance}  
    

提交回复
热议问题