473,569 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Subclassing built-in types

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__(s elf)

The above code does not allow the passing of a sequence to populate the
NewList.

I imagine that the correct way to do it is something like:

class NewList(list):
def __init__(self,s eq):
list.__init__(s elf,seq)

but I can't find any documentation that describes what arguments
list.__init__ may take.

Where can I find that documentation? I've looked through the manual but
can't find anything relevant. Google searches bring up articles that
talk about code as described in my first example but I can't find
anything like the second.
Jul 18 '05 #1
3 1594
Emiliano Molina wrote:
--- some stuff I was confused about ---
Where can I find that documentation? I've looked through the manual but
can't find anything relevant. Google searches bring up articles that
talk about code as described in my first example but I can't find
anything like the second.


I received no answers to my post (not complaining) and I am curious as
to wether it was a silly question or if there was no answer because what
I wanted to know is not documented.

Thanks for your replies (if there are going to be any!)
Jul 18 '05 #2

[Emiliano]
I am concerned about something like:

class NewList(list):
def __init__(self):
list.__init__(s elf)

The above code does not allow the passing of a sequence to populate the
NewList.

I imagine that the correct way to do it is something like:

class NewList(list):
def __init__(self,s eq):
list.__init__(s elf,seq)

but I can't find any documentation that describes what arguments
list.__init__ may take.


The safest way to do this is:

class NewList(list):
def __init__(self, *args, **kwargs):
list.__init__(s elf, *args, **kwargs)

That will work whatever arguments list.__init__ expects, and will continue
to work even if it changes in the future. It's useful when subclassing
anything that isn't under your control.

(In the trivial case above, where your __init__ doesn't do anything, you can
always just omit it.)

--
Richie Hindle
ri****@entrian. com

Jul 18 '05 #3
Thank you, thats just what I needed.
Jul 18 '05 #4

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

Similar topics

4
1842
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 something like : >>> t = Test('anAttributeValue', ) >>> t.anAttribute
2
1492
by: David Vaughan | last post by:
I'm using v2.3, and trying to write to text files, but with a maximum line length. So, if a line is getting too long, a suitable ' ' character is replaced by a new line. I'm subclassing the file class, and, as long as I just use the write method, this works fine. But "print >>" doesn't behave as I want: class max_width_file(file): def...
5
6476
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 database to track Computer equipment/inventory as well as other devices. Computers, of course, have software installed, so I want to keep track of...
2
2992
by: Alexander Wehrli | last post by:
Hi, I need to write a functionality to catch all Windows Messages from any Window (like spy++ does). I thought that would be possible by subclassing the window. So I wrote a class that inherts from NativeWindow, Assigned a Handle from another window and overrode the WndProc method. BUT, I never catch any message EXCEPT if I assign the...
0
926
by: Felbrigg | last post by:
Can anyone give me any pointers on Subclassing a TextBox. I do not want to create a UserControl.
1
1326
by: paul.hester | last post by:
Hi all, I'm planning to migrate a website from ASP to ASP .NET 2.0. The old page has a common include file that performs a series of tasks when every page loads. I'm new to ASP .NET 2.0 and am not sure of the best way to implement this. I'm considering subclassing the Page class so that all these tasks will automatically run without every...
6
1393
by: Its Me Ernest T. | last post by:
I am looking for any information about how I could subcass a form I don't own and resize some buttons. We run a application which is extreamly legacy and the company has long since went out of business. This application will install on WinXP but the buttons on the form are smaller than they should be. I would like to hook into this form...
2
1224
by: Paulo da Silva | last post by:
Hi! What's wrong with this way of subclassing? from datetime import date class MyDate(date): def __init__(self,year,month=None,day=None): if type(year) is str: # The whole date is here as a string
1
1402
by: Christian Heimes | last post by:
Rick King schrieb: datetime.date is a C extension class. Subclassing of extension classes may not always work as you'd expect it. Christian
5
2511
by: Ray | last post by:
Hi all, I am thinking of subclassing the standard string class so I can do something like: mystring str; .... str.toLower (); A quick search on this newsgroup has found messages by others
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5509
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.