Sparky Sparky - 5 months ago 8x
Python Question

Check for particular value from class object and get the value of another key

I have code implemented to reach the DB using CLI client.

I can be able to get the values as needed.

Consider the following code:

# Establish the connection Cloudkitty
ck = client.get_client(kwargs_conn.get('cloudkitty_version'), **kwargs_conn)

list_services =

for services in list_services:

print services

It will produce the output as follows:

<hashmap.Service {u'service_id': u'2c6e0447-0cdb-4d12-8511-4544ba0d03b5', u'name': u'compute'}>
<class 'cloudkittyclient.v1.rating.hashmap.Service'>
<hashmap.Service {u'service_id': u'48297131-de33-48ad-b5b5-43d3a3177841', u'name': u'volume'}>
<class 'cloudkittyclient.v1.rating.hashmap.Service'>

Output being retuned is used to be a class object.

Now here I need to check for the returned object for particular value for the key. To be precise I want to check that whether it have the 'name' as 'compute', If yes I need to get the service_id of the same.

Someone let me know how we can achieve the same.

Library used :


Looking at some of tests in the library, it seems you can directly access the fields like service_id:

for service in list_services:
    if == 'compute':

Or, if you want to get the service ids for all the services where name is compute:

service_ids = [service.service_id for service in list_services if == 'compute']