Personal Experience Flashcards

1
Q

Prevent KeyError

A

my_dict.get(‘key’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Prevent AttributeError

A

getattr(self.desired_group, 'date_from', None)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Prevent AttributeError for nested attributes

Safely check for attribute’s attribute

A

getattr(getattr(self.desired_group, 'education_program', None), 'age_from', None)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly