I'm parsing an HTML file and searching for status of order in it. Sometimes, status doesn't exist, so BeautifulSoup returns NoneType, when I'm using it. To solve this problem I use if-else statement, but it doesn't work too. Python returns:
TypeError: object of type 'NoneType' has no len()
I am adding status to a dictionary, which contains other info from the order. The code below is a part, which adds new order's info to a dict.
database.append({
"Title": title[0] + title.lower()[1:],
"Name": name[0].upper() + name[1:],
"Status": status.string[:len(status.string)-3] if status is not None else "Not listed",
"Price": price
})