>>> class StrictList(list):
... def __init__(self,content=None):
... if not content:
... self.content = []
... self.type = None
... else:
... content = list(content)
... cc = content[0].__class__
... if l_any(lambda x: x.__class__ != cc, content):
... raise Exception("List items must be of the same type")
... else:
... self.content = content
... self.type = cc
...
>>> x = StrictList([1,2,3,4,5])
>>> x
[]
>>> x.content
[1, 2, 3, 4, 5]
我想能夠調用x
時不x.content
我應該使用哪種方法?
我已經編輯到我是希望能更清楚一點...... – beoliver
*現在*您有:-) –
一個問題,異常會過得更好是一個TypeException,太! – Ben