473,385 Members | 1,487 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,385 software developers and data experts.

How do you control _all_ items added to a list?

Xif
Hi

I want to have control over all items added to a list.

The first attempt was to subclass list and override its .append()
method.

Problem is, there are plenty of other ways the list can have items
added to it - e.g. extend, insert - and theyr'e not at all affected by
the changes I made to append.

Is there some "base" item-adding method that all other item-adding
methods use, so I can override it and have the changes affect all
item-adding functions?

Thanks,
Xif

Jul 18 '05 #1
3 1576

Xif wrote:
Hi

I want to have control over all items added to a list.

The first attempt was to subclass list and override its .append()
method.

Problem is, there are plenty of other ways the list can have items
added to it - e.g. extend, insert - and theyr'e not at all affected by the changes I made to append.

Is there some "base" item-adding method that all other item-adding
methods use, so I can override it and have the changes affect all
item-adding functions?

If you subclass list then you will need to override all methods that
can set items. This is because the built in methods work directly with
the internal structure and are implemented in C. It's a bit of a
pain... but not that much.

Regards,

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


Jul 18 '05 #2
Xif
Quoting Fuzzyman:

"If you subclass list then you will need to override all methods that
can set items."
Overiding all those methods is too much of an effort. I don't really
need them.

I'll just have an object that uses a list internally, and define only
the two methods I really need: extend() and getItems().

That way I retain full control over what goes into the private
obj._list, without the superfluous work of overriding all those methods
I don't really need.

Thanks for your help,
Xif

Jul 18 '05 #3
Xif wrote:
Overiding all those methods is too much of an effort. I don't really
need them.


Hmm, it might be nice if there was a UserList.ListMixin that was the counterpart
to UserDict.DictMixin that let's you provide the full dictionary API with just
__getitem__, __setitem__, __delitem__ and keys()

With an appropriate ListMixin, providing the first three methods would suffice
to support the full list API.

Cheers,
Nick.

--
Nick Coghlan | nc******@email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
Jul 18 '05 #4

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

Similar topics

2
by: Steven Bethard | last post by:
Nick Coghlan wrote: > Hmm, it might be nice if there was a UserList.ListMixin that was the > counterpart to UserDict.DictMixin I've thought this occasionally too. One of the tricky issues...
3
by: Chris Newby | last post by:
I have a very simple custom control that derives from WebControls.Panel and implements INamingContainer. It appear that controls created as children of my custom control are having ViewState...
5
by: mytestemailaccount | last post by:
Hi, Hope you can help. I am relatively new to all this but would appreciate the groups help. The scenario: I am c# and asp.net to create a web application. The web page contains a user...
7
by: Buddy Ackerman | last post by:
I created this class Public Class HTMLFileInput : Inherits System.Web.UI.HtmlControls.HtmlInputFile Public Property Data As String Get Return ViewState("HTMLFileInput.Data") End Get Set...
9
by: James Radke | last post by:
Hello, I would like to create a sorted listbox which has one property that I can set to true or false to show if the listbox should be sorted (I may potentially add another one for the sort...
12
by: Dennis | last post by:
I have a form which has a ListView control named ListView1 added at design time. When I add items using the following code, they don't appear in the list view. However, if I create a ListView...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
1
by: shapper | last post by:
Hello, I have a class where I created various controls. One of the controls have a property which is a generic list of WebControl. Then in web site page I have something like: Dim a As New...
2
by: =?Utf-8?B?SmFzb24gQmFybmV0dA==?= | last post by:
I've created a component that inherits from ComboBox. Wiithin its constructor, I've hardcoded some initial items that I'd like added. These items are of a custom class. When I add my control...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.