This blows my mind. What am I missing?
I am trying to detect if a cell in an Excel sheet is empty or not. But none of the tests seem to work in the way I expect. I would expect that the simple "not idkt" test would detect both empty strings and None, but no... In fact, it seems like None is not detected by - well - any of the tests, because in the third row, that's what is getting printed.
Code:
def getFromExcelSheet():
wb = load_workbook("input.xlsx")
idkts = [];
idktRows = get_worksheet_as_list(wb.get_sheet_by_name('Inputs'))
# print "Got these idkts"
for row in idktRows:
# print row[0]
idkt = str(row[2]).strip()
filename = str(row[3]).strip()
if idkt == None:
print "Idkt == none"
if idkt is None:
print "Idkt is none"
if idkt == u"":
print "Idkt is ''"
if idkt != u"":
print "Idkt is !=''"
if not idkt:
print "not IDKT"
if idkt:
print "idkt"
print idkt
Output
Idkt is !=''
idkt
3398041577
Idkt is !=''
idkt
3498100937
Idkt is !=''
idkt
None
print repr(idkt)on the last line?'around it, it is a string (and not theNoneconstant...)