编写类定义最惯用的方法是什么?我下面的代码不可能是最好的方法。
class Course:
crn = course = title = tipe = cr_hours = seats = instructor = days = begin = end = location = exam = ""
def __init__(self, pyQueryRow):
self.crn = Course.get_column(pyQueryRow, 0)
self.course = Course.get_column(pyQueryRow, 1)
self.title = Course.get_column(pyQueryRow, 2)
self.tipe = Course.get_column(pyQueryRow, 3)
self.cr_hours = Course.get_column(pyQueryRow, 4)
self.seats = Course.get_column(pyQueryRow, 5)
self.instructor = Course.get_column(pyQueryRow, 6)
self.days = Course.get_column(pyQueryRow, 7)
self.begin = Course.get_column(pyQueryRow, 8)
self.end = Course.get_column(pyQueryRow, 9)
self.location = Course.get_column(pyQueryRow, 10)
self.exam = Course.get_column(pyQueryRow, 11)
def get_column(row, index):
return row.find('td').eq(index).text()
[首先,python 是一门很棒的语言。这是我第一个使用 python 的项目,我已经取得了可笑的进步。]