473,326 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

subclassing list

Hi,

I want to subclass "list". The documentation states to prefer subclassing
list instead of UserList. How to you clear the contents of a list subclass
without creating a new object?

Thanks in advance
Uwe
Jul 18 '05 #1
2 1888
class newList(list):
def clear(self):
self[:] = []

is one way.
HTH

Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

Jul 18 '05 #2

[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
ri****@entrian.com

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: GrelEns | last post by:
hello, i wonder if this possible to subclass a list or a tuple and add more attributes ? also does someone have a link to how well define is own iterable object ? what i was expecting was...
13
by: Chris Cioffi | last post by:
Hello all! I'm trying to subclass int such that once it reaches a certain value, it flips back to the starting count. This is for use as an X12 control number. Subclassing int and getting the...
3
by: Emiliano Molina | last post by:
Where can I find information on how to do this? Specifically I am concerned about something like: class NewList(list): def __init__(self): list.__init__(self) The above code does not allow...
2
by: BJörn Lindqvist | last post by:
A problem I have occured recently is that I want to subclass builtin types. Especially subclassing list is very troublesome to me. But I can't find the right syntax to use. Take for example this...
12
by: Jane Austine | last post by:
Please see the following code: -------------------------------- class rev_wrap(object): def __init__(self,l): self.l=l def __getitem__(self,i): return self.l class rev_subclass(list): def...
5
by: Pieter Linden | last post by:
Hi, This question refers sort of to Rebecca Riordan's article on Access web about subclassing entities: http://www.mvps.org/access/tables/tbl0013.htm How practical is this? I am writing a...
4
by: David Coffin | last post by:
I'd like to subclass int to support list access, treating the integer as if it were a list of bits. Assigning bits to particular indices involves changing the value of the integer itself, but...
3
by: jackstah | last post by:
I've read before that subclassing off of std::vector is a bad idea because it's a concrete class. I understand, but there shouldnt be any issues with this. I just wanted to do a simple example in...
5
by: Mike Kent | last post by:
For Python 2.5 and new-style classes, what special method is called for mylist = seq and for del mylist (given that mylist is a list, and seq is some sequence)? I'm trying to subclass list, and...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.