我遇到了一个问题“int()与基数10的无效文字:''”,这意味着python无法将“'转换为整数。但是我已经添加了一个条件if(sh.cell_value(rowx=rx, colx=3)!=''):
,它可以跳过不包含任何内容的块。有没有人有一些想法?非常感谢你!int()与基数为10的无效字面值:''
import xlrd
book = xlrd.open_workbook("streeteasy.xls")
sh = book.sheet_by_index(0)
total = 0
for rx in range (sh.nrows):
if(sh.cell_value(rowx=rx, colx=3)!=''):
s = sh.cell_value(rowx=rx, colx=3)
print filter(unicode.isdigit, s)
print int(filter(unicode.isdigit, s))
total += int(filter(unicode.isdigit, s))
如果您引用的错误消息是实际错误消息,则该字符串不为空。它包含一个空间。另外,即使你的if语句块没有执行,你仍然继续循环的其余部分,并尝试在's'上调用'int'。 – BrenBarn
检查'如果string.strip()',这将删除与空格... –
@BrenBarn除非发布后忍者编辑后,你的评论,我认为你误读。 ''''是空字符串 - 没有空格。 – sepp2k