2

type(harvest.clients()) 输出:列表

harvest.clients()[0] 输出:

OrderedDict([(u'client',
              OrderedDict([(u'id', 2793223),
                           (u'name', u'1 TEMPLATES'),
                           (u'active', True),
                           (u'currency', u'Australian Dollar - AUD'),
                           (u'updated_at', u'2014-09-14T22:48:29Z'),
                           (u'created_at', u'2014-09-14T22:48:29Z'),
                           (u'default_invoice_timeframe', None),
                           (u'address', u''),
                           (u'currency_symbol', u'$'),
                           (u'details', u''),
                           (u'last_invoice_kind', None)]))]

如何访问客户 ID、名称、活动、货币等?

4

2 回答 2

2
client = harvest.clients()[0]['client']
print(client['id'])
print(client['name'])
print(client['active'])
print(client['currency'])

参考https://docs.python.org/3/library/collections.html#collections.OrderedDict

于 2018-05-09T01:51:01.947 回答
0

尝试以下代码循环您的有序字典:

for key,value in o['client'].items():
    print(key,value)

输出:

id 2793223
name 1 TEMPLATES
active True
currency Australian Dollar - AUD
updated_at 2014-09-14T22:48:29Z
created_at 2014-09-14T22:48:29Z
default_invoice_timeframe None
address 
currency_symbol $
details 
last_invoice_kind None
于 2018-05-09T01:56:53.423 回答