I have this code:    lengths = []    lengths.append(len(self.download_links))    lengths.append(len(self.case_names))    lengths.append(len(self.case_dates))    lengths.append(len(self.docket_numbers))    lengths.append(len(self.neutral_citations))    lengths.append(len(self.precedential_statuses))Unfortunately, any of those object properties can be None, so I need to check each with either an if not None block or a try/except block. Checking each individually will blow up the size and conciseness of the code. I assume there must be a better way for this kind of pattern, right?
Better way to do multiple try/except in Python
python
Firstly, consider whether these shouldn't be None, but instead should be empty lists. Most of the time None is better replaced by something else like an empty list.If that's not an option, you can use a list:for item in [self.download_links, self.case_name...]:    if item is not None:         length.append( len(item) )or a functiondef add_length(obj):   if obj is not None:            lengths.append(len(obj))add_length(self.download_links)add_length(self.case_name)...