A list comprehension would work just fine:

[o.my_attr for o in my_list]

But there is a combination of built-in functions, since you ask :-)

from operator import attrgetter
map(attrgetter('my_attr'), my_list)
Answer from Jarret Hardie on Stack Overflow
🌐
LabEx
labex.io › tutorials › python-how-to-retrieve-python-object-data-420265
How to retrieve Python object data | LabEx
try: value = getattr(student, 'unknown_attribute') except AttributeError: print("Attribute not found") ... By mastering these techniques, you'll efficiently retrieve and manage object data in Python with LabEx's recommended approaches.
🌐
AllInterview
allinterview.com › showanswers › 189459 › what-is-the-procedure-to-extract-values-from-the-object-used-in-python.html
What is the procedure to extract values from the object used in python?
The values will be extracted as: • If the object is a tuple then PyTuple_Size() method is used that returns the length of the values and another method PyTuple_GetItem() returns the data item that is stored at a specific index. • If the object is a list then PyListSize() is having the same ...
🌐
Stack Overflow
stackoverflow.com › questions › 69469337 › how-to-extract-the-value-of-an-object-in-python
pandas - How to extract the value of an object in Python? - Stack Overflow
October 6, 2021 - I want to get the single value out of the object output which is "bitcoin" in my case but when i run the code, it only returns me an object pair value. import pandas as pd from pycoingecko import CoinGeckoAPI cg = CoinGeckoAPI() dflist=pd.DataFrame(cg.get_coins_list()) dflist["id"].loc[dflist['symbol'] == "btc"]
🌐
Stack Overflow
stackoverflow.com › questions › 42665347 › how-to-extract-values-from-a-json-object-with-python
How to extract values from a json object with python? - Stack Overflow
March 8, 2017 - cast_and_crew =[ {'characterName':'','creditType':'Actor','personName':'M.A.Nadiadwala'}, {'characterName': '', 'creditType': 'Actor', 'personName': 'Gyandev Agnihotri'}, {'characterName': '', 'creditType': 'Actor', 'personName': 'Rakesh Kumar'} ] for data in cast_and_crew: # for python3 use print(data.get('personName')) print data.get('personName') ... Sign up to request clarification or add additional context in comments. ... i'm getting error - AttributeError: 'tuple' object has no attribute 'get' 2017-03-09T05:29:10.72Z+00:00
🌐
DNMTechs
dnmtechs.com › extracting-attributes-from-objects-in-python-3
Extracting Attributes from Objects in Python 3 – DNMTechs – Sharing and Storing Technology Knowledge
By using the dir() and getattr() functions, we can extract all the attributes of an object and retrieve their values dynamically. This flexibility enables us to build more flexible and robust applications that can adapt to different scenarios. The getattr() function in Python allows us to extract ...
🌐
Stack Abuse
stackabuse.com › bytes › get-all-object-attributes-in-python
Get All Object Attributes in Python
August 24, 2023 - In Python, every object is equipped with a __dict__ attribute. This built-in attribute is a dictionary that maps the object's attributes to their respective values. This can be very handy when we want to extract all properties and values of an object.
Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-getattr
Python getattr() | DigitalOcean
August 3, 2022 - Python getattr() function is used to get the value of an object’s attribute and if no attribute of that object is found, default value is returned. Basically, returning the default value is the main reason why you may need to use Python getattr() function.
🌐
Python Guides
pythonguides.com › json-data-in-python
How To Get Values From A JSON Array In Python?
November 29, 2024 - We can access the individual values of each object using the corresponding keys, such as state['name'], state['capital'], and state['population']. The output will be: State: California Capital: Sacramento Population: 39512223 --- State: Texas Capital: Austin Population: 28995881 --- State: ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › extract-elements-from-a-python-list
Extract Elements from a Python List - GeeksforGeeks
July 23, 2025 - When working with lists in Python, we often need to extract specific elements. The easiest way to extract an element from a list is by using its index.
🌐
Finxter
blog.finxter.com › home › learn python blog › 6 easy ways to extract elements from python lists
6 Easy Ways to Extract Elements From Python Lists - Be on the Right Side of Change
July 6, 2022 - prices = [17.91, 19.71, 18.55, 18.39, 19.01, 20.12, 19.87] all_prices = [x for x in prices] print(all_prices) Above declares a List containing the previous week’s stock prices (Sunday-Saturday) and saves to prices. Next, List Comprehension is used to loop and extract all price values.
🌐
Iditect
iditect.com › faq › python › how-to-extract-from-a-list-of-objects-a-list-of-specific-attribute-in-python.html
How to extract from a list of objects a list of specific attribute in python?
We then use either a list comprehension or the map() function to extract the specified attribute (in this case, 'name') from each object in the list. The result is a list containing the extracted values of the specified attribute. You can replace 'name' with the name of the attribute you want ...
Top answer
1 of 5
91

For reference, let's see what the original JSON would look like, with pretty formatting:

>>> print(json.dumps(my_json, indent=4))
{
    "name": "ns1:timeSeriesResponseType",
    "declaredType": "org.cuahsi.waterml.TimeSeriesResponseType",
    "scope": "javax.xml.bind.JAXBElement$GlobalScope",
    "value": {
        "queryInfo": {
            "creationTime": 1349724919000,
            "queryURL": "http://waterservices.usgs.gov/nwis/iv/",
            "criteria": {
                "locationParam": "[ALL:103232434]",
                "variableParam": "[00060, 00065]"
            },
            "note": [
                {
                    "value": "[ALL:103232434]",
                    "title": "filter:sites"
                },
                {
                    "value": "[mode=LATEST, modifiedSince=null]",
                    "title": "filter:timeRange"
                },
                {
                    "value": "sdas01",
                    "title": "server"
                }
            ]
        }
    },
    "nil": false,
    "globalScope": true,
    "typeSubstituted": false
}

That lets us see the structure of the data more clearly.

In the specific case, first we want to look at the corresponding value under the 'value' key in our parsed data. That is another dict; we can access the value of its 'queryInfo' key in the same way, and similarly the 'creationTime' from there.

To get the desired value, we simply put those accesses one after another:

my_json['value']['queryInfo']['creationTime'] # 1349724919000
2 of 5
23

I just need to know how to translate that into specific code to extract the specific value, in a hard-coded way.

If you access the API again, the new data might not match the code's expectation. You may find it useful to add some error handling. For example, use .get() to access dictionaries in the data, rather than indexing:

name = my_json.get('name') # will return None if 'name' doesn't exist

Another way is to test for a key explicitly:

if 'name' in resp_dict:
    name = resp_dict['name']
else:
    pass

However, these approaches may fail if further accesses are required. A placeholder result of None isn't a dictionary or a list, so attempts to access it that way will fail again (with TypeError). Since "Simple is better than complex" and "it's easier to ask for forgiveness than permission", the straightforward solution is to use exception handling:

try:
    creation_time = my_json['value']['queryInfo']['creationTime']
except (TypeError, KeyError):
    print("could not read the creation time!")
    # or substitute a placeholder, or raise a new exception, etc.
🌐
Medium
mike-vincent.medium.com › quarks-outlines-python-object-value-1e8496120920
Quark’s Outlines: Python Object Value | by Mike Vincent | Medium
June 16, 2025 - Solution: Use == to compare the value inside each object. Python lets you compare object values with ==.
🌐
Python.org
discuss.python.org › python help
Extract values from a def() - Python Help - Discussions on Python.org
March 8, 2023 - Q1. How can I extract values from a def() function? Specifically, in these instances, either a or b values. def absoluteA (a): a = abs(a) b = -a return (b,a) print(absoluteA(4)) def absoluteB (a): a = abs(a) b = -abs(a) return (b,a) print(absoluteB(5)) # result (-4, 4) (-5, 5) Q2: How do I multiply two set of numbers?
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-program-to-extract-a-single-value-from-json-response
Python program to extract a single value from JSON response - GeeksforGeeks
July 23, 2025 - The base URL is combined with the final URL, which includes both currencies, to fetch the result. An API call is then sent. The data is obtained by accessing the JSON Data's "conversion rate" key, and the resulting conversion rate is then printed.
🌐
Towards Data Science
towardsdatascience.com › home › latest › how to extract nested dictionary data in python?
How to extract Nested Dictionary Data in Python? | Towards Data Science
March 5, 2025 - The usage of the term data type in Python is not of less importance however it does not convey the same meaning as a key to understanding nested data extraction. One of the best ways to learn is by working through real data with a mix of list and dictionary data structures. In this tutorial, we’ll use real data from the REST Countries API. This API returns about 250 records with a mix of dictionaries, lists and other data types. Our objective is to extract the 'AFN' value from the dictionary key-value pair 'code':'AFN' as shown in the image below.