subclassing list

Richie Hindle richie at entrian.com
Thu Dec 23 09:48:16 EST 2004


[Uwe]
> How [do] you clear the contents of a list subclass
> without creating a new object?

Use the paranoia emoticon: "del x[:]".  For example:

>>> class L(list):
...   pass
...
>>> x = L()
>>> x.append("Spam")
>>> del x[:]
>>> x
[]
>>> type(x)
<class '__main__.L'>
>>>

with-thanks-to-Gordon-McMillan-ly y'rs,

-- 
Richie Hindle
richie at entrian.com




More information about the Python-list mailing list