3
針對a previous question我有,我現在有想知道它是做下面的代碼的任何方式更好看:有沒有更好的方式來編寫這段代碼來改變從Python中的`list`繼承的對象?
class Cycle(list):
def insertextend(self, index, other, reverse = False):
"""Extend the cycle by inserting an iterable at the given position."""
index %= len(self)
if reverse:
super(Cycle, self).__init__(self[:index] + list(reversed(other)) + self[index:])
else:
super(Cycle, self).__init__(self[:index] + other + self[index:])
任何想法,我怎麼能刪除super(Cycle, self).__init__(...)
?
你只是想避免使用'super'?你希望在這裏獲得什麼? –
每當我想要改變Cycle中的數據時,對我來說,只要調用list的'__init__'就會覺得有點麻煩。我只是想知道我是否正確。 – user3002473
以下內容的用途是什麼? 'index%= len(self)' –