任何人都可以幫助我理解爲什麼這是給我一個錯誤?錯誤是「NameError:name'self'未定義」。我的代碼中有更高的類似類,並且工作正常?NameError:name'self'沒有被定義,即使它是?
我使用'xlrd',團隊是對workbook.sheet_by_name的引用。
class Rollout:
def __init__(self, team, name):
self.team = team
self.name = name
self.jobs = {}
self.start_row = 1
self.last_row = self.team.nrows
for i in range(self.start_row,self.last_row):
try:
self.jobs[i-1] = [str(self.team.cell_value(i,0)).upper(), \
str(self.team.cell_value(i,1)).upper(), \
str(self.team.cell_value(i,2)).upper(), \
str(self.team.cell_value(i,3)).upper(), \
str(xlrd.xldate_as_tuple(self.team.cell_value(i,4),0)[3]), \
str(self.team.cell_value(i,5)).upper(), \
str(self.team.cell_value(i,6)).upper()]
except ValueError:
print "It look's like one of your 'time' cells is incorrect!"
self.jobs[i-1] = [str(self.team.cell_value(i,0)).upper(), \
str(self.team.cell_value(i,1)).upper(), \
str(self.team.cell_value(i,2)).upper(), \
str(self.team.cell_value(i,3)).upper(), \
"missing", \
str(self.team.cell_value(i,5)).upper(), \
str(self.team.cell_value(i,6)).upper()]
縮進是否正確? –
for循環沒有正確縮進 –
如果'self'沒有定義,那麼你不在裏面的方法.. –