0

I am attempting to print the value of "age" in stored in the info attribute within a dynamodb. Below is a sample data set along with the code I am using. I recieve an error: "KeyERROR: 'info.age'. I have tried several different variations and all unsuccessful.

Here is code where I query the database and try to print output:

response = table.query(
    KeyConditionExpression=Key('bourbon_id').eq("Four Roses") )

for i in response['Items']:
    print(i['bourbon_id'], ":", i['source_id'], ":", i['info.age'])

Here is example data:

"bourbon_id": "Four Roses",
"source_id": "Liquor Barn",
"info":{
    "age": 11,      
    "proof": 124,
    "open": 1,
    "closed": 0,
    "barrled": "June 12 2002",
    "bottled": "December 15 2013",
    "description": "OESK"

If I remove the age, it prints out all items within info.. How can I get just the value of age to print?

for i in response['Items']:
    print(i['bourbon_id'], ":", i['source_id'], ":", i['info'])

1 Answer 1

1

The syntax for referencing items in dict in your case is i["info"]["age"]. Python doesn't have dot notation for accessing members of a dict.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.