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

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__(self)

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,seq):
list.__init__(self,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 1584
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__(self)

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,seq):
list.__init__(self,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__(self, *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
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...
2
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...
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...
2
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...
0
by: Felbrigg | last post by:
Can anyone give me any pointers on Subclassing a TextBox. I do not want to create a UserControl.
1
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...
6
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...
2
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...
1
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
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
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.