Overriding append method after inheriting from a Python List

前端 未结 6 1739
长情又很酷
长情又很酷 2020-11-27 17:33

I want to create a list that can only accept certain types. As such, I\'m trying to inherit from a list in Python, and overriding the append() method like so:



        
6条回答
  •  感情败类
    2020-11-27 18:17

    instead of self.append(item) use super(TypedList, self).append(item) (see http://docs.python.org/library/functions.html#super)

提交回复
热议问题