我有一個錯誤:當我運行這段代碼NameError: name 'convert_symbol_to_int' is not defined
:NameError:名字「convert_symbol_to_int的」沒有定義
class ReadData():
def __init__(self, sheet_path):
self.book = xlrd.open_workbook(sheet_path)
self.sheet = self.book.sheet_by_index(1)
self.users = []
def read(self):
for row_index in range(2, self.sheet.nrows):
rows = self.sheet.row_values(row_index)
if rows[1] != '' and rows[2] != '' and rows[4] != '':
woman = convert_symbol_to_int(row[8])
man = convert_symbol_to_int(row[9])
def convert_symbol_to_int(self,arg):
if arg == '○':
return 2
elif arg == '×':
return 1
elif arg == '△':
return 0
else:
return -1
x = ReadData('./data/excel1.xlsx')
x.read()
我真的不明白,爲什麼這個錯誤發生。 爲什麼我不能訪問convert_symbol_to_int
?我應該如何解決這個問題?