class Runner:
"""
information of registered runners
Attributes:
@type email: str
email of the registered runner
@type category: str
the speed they estimate that they can finish the race
@type list: clist
the list of runners in the same category
"""
under_twenty_min = []
under_thirty_min = []
under_forty_min = []
forty_and_above = []
def __init__(self, email, category):
"""Register the email and the speed estimation of runners
@type self: Runner
@type email: str
@type speed: int
@type category:str
@type clist: list
@rtype: list
>>>runner1=Runner('[email protected]','under 40 min')
>>>runner1.email
'[email protected]'
>>>runner1.category
'under 40 min'
"""
self.email = email
self.category = category
if category=='under 20 min':
self.clist=under_twenty_min
elif category=='under 30 min':
self.clist = under_twenty_min
elif category=='under 40 min':
self.clist = under_forty_min
elif category=='40 min and over':
self.clist = forty_and_over
renew(self,clist)
return clist
В основном я должен вернуть список бегунов с одинаковой скоростью, когда инициализируется бегун, но я не могу назначить перечисленные выше списки атрибуту класса, есть ли все равно, чтобы исправить его?Python: Я не могу назначить определенный список атрибуту класса?
в acceess атрибуты пространства имен классов используют это обозначение 'self.clist = Runner.under_twenty_min' –
' '' вернуть clist''' -> '' 'обратный self.clist''' и' '' renew (self, clist) '' '->' '' renew (self, self.clist) '' '. Вероятно, вы должны показать нам '' 'renew''' - это метод класса или * автономной * функции? – wwii
Странно, что '' '__init__'' должен вернуть список - http://stackoverflow.com/a/2491831/2823755 – wwii