我正在与python boto package called mws合作,与Amazon MWS进行接口。但我觉得这也是一个一般的python问题,还是不确定。我使用list_oder_items
方法获取订单的产品项。在
items = conn.list_order_items(AmazonOrderId = order_id)
result = items.ListOrderItemsResult
然后我要保存每个项目。在
^{pr2}$这里的item
变量是一个<class 'boto.mws.response.OrderItem'>
类型,如果打印出来,会显示如下:
OrderItem{}(Title: u'title', GiftWrapPrice: USD 0.00, ConditionNote: u'Brand New& Authentic product....', CODFee: None, ASIN: u'XXXX', OrderItemId: u'XXXX', CODFeeDiscount: None, QuantityShipped: u'1', GiftWrapTax: USD 0.00, ShippingPrice: USD 3.99, QuantityOrdered: u'1', ItemTax: USD 0.00, PromotionIds: [], SellerSKU: u'XXXX', ShippingDiscount: USD 0.00, ShippingTax: USD 0.00, ConditionId: u'New', PromotionDiscount: USD 0.00, ItemPrice: USD 12.81, ConditionSubtypeId: u'New')
为什么我不能像for key in item: print key
那样迭代键值对?只是有点傻,虽然我也试过这个:for key in dict(item): print key
。也没有打印任何东西。在
我只想有一个更系统的方法来处理item
对象,而不是目视检查。有没有可能把它变成一个普通的python dict?在
基本上你得到了一个对象,你想在这个对象的所有字段上迭代key:值对。在
您可以尝试object.
_dict_
来获取对象的字典表示。在代码示例:
相关问题 更多 >
编程相关推荐