dictionary - getting key-value pairs of custom object in python -


i working python boto package called mws interfacing amazon mws. think general python question, still not sure. using list_oder_items method product items order.

items = conn.list_order_items(amazonorderid = order_id) result = items.listorderitemsresult 

then want save each item.

for item in result.orderitems.orderitem:     save_item_to_db(item) 

here item variable type <class 'boto.mws.response.orderitem'>, if print out shows this:

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')

why can't iterate on key-value pairs for key in item: print key? silly though tried this: for key in dict(item): print key. didn't print either.

i have more systematic approach dealing item object visual inspection. possible turn normal python dict?

basically getting object , want iterate on fields of object key:value pair.

you can try object._dict_ dictionary representation of object.

code example:

for key in item.__dict__:     print key 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -