473,405 Members | 2,415 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,405 software developers and data experts.

Inheritting Built In Types

I am attempting build an object which inherits from the built in list
object. Essentially I need to do something every time data is added or
changed in a list. I have all the over ridding functions working
excepting for the functions that over ride the "set slice"
functionalitity. For example:

x[1:3] = [6,7]

I consulted the reference manual:
http://docs.python.org/ref/sequence-methods.html

It states that there is a __setslice__ method which is depricated since
release 2.0. The depricated function works, but I do not want to
implement ontop of functionality that is marked to be removed. "If no
__setslice__() is found a slice object is created, and passed to
__setitem__()". I executed the below code sample to check this
behavior.

class newlist(list):
def __setitem__(self, i, data):
if isinstance(data, slice):
print "Received Slice Object"
list.__setitem(self, i, data)

if __name__ == "__main__":
x = newlist([1,2,3,4,5])
x[1:3] = [6,7]
print x

On a Windows XP machine wiht Python 2.3.5 and a Linux server with
Python 2.4.2 I receive the following output:
[1, 6, 7, 4, 5]
My print statement never gets executed.

Am I checking for the slice object incorrectly? That's the only thing
I can think of.

-Mark

Aug 16 '06 #1
1 1468
Digital Logic wrote:
Am I checking for the slice object incorrectly? That's the only thing
I can think of.
Yes. The slice object is the "i" variable in your code, not the "data"
variable.

-Farshid
Aug 16 '06 #2

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

Similar topics

3
by: Howard | last post by:
Hi, I am maintaining a lot of code that is rife with C-style casts. I've seen a lot of comments that one should not use C-style casts at all. But I'm wondering what harm there could be in...
9
by: Pierre Senellart | last post by:
The C++ standard states (26.3.2.1), about std::valarray constructors: > explicit valarray(size_t); > > The array created by this constructor has a length equal to the value of > the argument....
6
by: Alan Johnson | last post by:
For various reasons I'd like to be able to inherit from the built in types, which obviously you cannot do. To get around this, I made a template to emulate the built in types. So far I can't find...
3
by: lovecreatesbeauty | last post by:
Prof. Bjarne Stroustrup said "built-in data types have default constructor" at §10.4.2 in `TC++PL, special ed.'. He also said that "built-in data types are not classes" at §11.4 in `TC++PL,...
0
by: foxhu | last post by:
i build a class inheritting from the dataset on server public class Order:DataSet { public int OrderCount; public string OrderNumber; public Order() { }
2
by: Alona | last post by:
Hello, Does W3C defines a standard for mapping XML types to C/C++ built-in types and vise versa? Thank you, Alona
55
by: tonytech08 | last post by:
How valuable is it that class objects behave like built-in types? I appears that the whole "constructor doesn't return a value because they are called by the compiler" thing is to enable...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.