Help with blanks in Date field?

Hi there,

I have a python code like below

  if row['Inspection Date'] == None:
            list_row.append(None)
            list_row.append(None)
            list_row.append(None)
      
        else:
            list_row.append(row['Inspection Date'][0:4])
            list_row.append(row['Inspection Date'][5:7])
            x = int(row['Inspection Date'][5:7])-1
            list_row.append(month_names[x])

Getting this error

Traceback (most recent call last):
  File "C:\Python Scripts\Production\Python Scripts\HSE - MyOsh Inspection Month Form Name.py", line 189, in <module>
    x = int(row['Inspection Date'][5:7])-1
ValueError: invalid literal for int() with base 10: ''

Because the data got blank values
image

How can I handle blank in the mentioned code.

How would you like it to handle a blank? Should it treat it like NULL (None in Python)?

Hi Matthew,
Just wondering then why I am getting this error at line
line 189, in
x = int(row[‘Inspection Date’][5:7])-1
ValueError: invalid literal for int() with base 10: ‘’

It’s because row['Inspection Date'][5:7] is an empty string, presumably because row['Inspection Date'] is an empty string.

Looking at the screenshot of the spreadsheet, it appears that the cell is empty, but it might actually contain an empty string.