Instead of deleting the empty string, you could just not append it.
The code could look like this:
datatable = []
for record in table.find_all('tr', class_="mytable"):
temp_data = []
for data in record.find_all("td"):
if data.text != "": #Check if the data is an empty string or not
temp_data.append(data.text.encode('latin-1')) #Append the data if it is not an empty string
datatable.append(temp_data)
#print(datatable)
#[["TEXT1"," TEXT2","TEXT3","TEXT4","TEXT5 ","TEXT6"],["TEXT7"," TEXT8","TEXT9","TEXT10","TEXT11","TEXT12"]]
This works well, but if you still want to delete the empty string after adding it to the list then you can do that as follows:
datatable = []
for record in table.find_all('tr', class_="mytable"):
temp_data = []
for data in record.find_all("td"):
temp_data.append(data.text.encode('latin-1'))
datatable.append(temp_data)
#print(datatable)
#[["TEXT1"," TEXT2","TEXT3","TEXT4","TEXT5 ","","TEXT6"],["TEXT7"," TEXT8","TEXT9","TEXT10","TEXT11","","TEXT12"]]
#Now remove the empty strings from datatable
for i in range(len(datatable)):
datatable[i] = filter(None, datatable[i])
#Since filter returns a filter object (iterator) in Python 3x, use
#datatable[i] = list(filter(None, datatable[i]))
#to convert it to list in Python 3x
#print(datatable)
#[["TEXT1"," TEXT2","TEXT3","TEXT4","TEXT5 ","TEXT6"],["TEXT7"," TEXT8","TEXT9","TEXT10","TEXT11","TEXT12"]]