0

Consider python code (python 3.7)

def status(event, context):
    for key, value in event.items():
        print(key, value)
    print (event)
    print (event.statuses)

This produce the output:

statuses ['SUCCESS', 'SUCCESS']
{'statuses': ['SUCCESS', 'SUCCESS']}
[ERROR] AttributeError: 'dict' object has no attribute 'statuses'
Traceback (most recent call last):
  File "/path/my_func.py", line 11, in status
    print (event.statuses)

It prints key statuses during iteration but . operator does not work. Any ideas?

Cherry
  • 31,309
  • 66
  • 224
  • 364
  • 2
    The dot operator isn't how values are accessed via keys. Perhaps you are confusing Python and JavaScript. Just use `event['statuses']`. – John Coleman Aug 16 '20 at 09:40
  • But in total `dict['key]` work by default but `dict.key` does not? – Cherry Aug 16 '20 at 09:50
  • It's worthwhile running through structured materials when picking up a new language: https://docs.python.org/3/tutorial/datastructures.html#dictionaries – jonrsharpe Aug 16 '20 at 09:50
  • `dict.key` might be useful and there are languages where that would work, but Python isn't one of them. The question that @jonrsharpe gives as a duplicate gives various ways of defining a dict-like class where it would work. – John Coleman Aug 16 '20 at 09:53

0 Answers0