473,670 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with syntax on inheritance.

If you are deriving a new class from another class,
that you must (I assume) know the initializer of the other class.

So in myClass

import array
class myClass(arrary. array):
def __init__(self, now here I need to put array's constructor
parameters..., then mine):
array.array.__i nit__(self, typecode[, initializer])
self.mine = mine

So I'm confused...
array has a typecode parameter and an optional initiializer...
So could you help me with the class construction here please?

Oct 4 '06 #1
5 1190

SpreadTooThin wrote:
If you are deriving a new class from another class,
that you must (I assume) know the initializer of the other class.

So in myClass

import array
class myClass(arrary. array):
def __init__(self, now here I need to put array's constructor
parameters..., then mine):
array.array.__i nit__(self, typecode[, initializer])
self.mine = mine

So I'm confused...
array has a typecode parameter and an optional initiializer...
So could you help me with the class construction here please?
Lookup *args and **kargs in the python reference manual.

Oct 4 '06 #2
On 3 Oct 2006 19:09:53 -0700, SpreadTooThin <bj********@gma il.comwrote:
If you are deriving a new class from another class,
that you must (I assume) know the initializer of the other class.

So in myClass

import array
class myClass(arrary. array):
def __init__(self, now here I need to put array's constructor
parameters..., then mine):
array.array.__i nit__(self, typecode[, initializer])
self.mine = mine

So I'm confused...
array has a typecode parameter and an optional initiializer...
So could you help me with the class construction here please?
If you need to take the same parameters as your super-class, and it
includes optional positional parameters, then simply call with
keywords to avoid the optional parameter:

myClass(typecod e, mine=something)

It has less to do with defining the parameters than calling the function.
Oct 4 '06 #3
SpreadTooThin wrote:
If you are deriving a new class from another class,
that you must (I assume) know the initializer of the other class.

So in myClass

import array
class myClass(arrary. array):
def __init__(self, now here I need to put array's constructor
parameters..., then mine):
array.array.__i nit__(self, typecode[, initializer])
self.mine = mine

So I'm confused...
array has a typecode parameter and an optional initiializer...
So could you help me with the class construction here please?
Normally you would do

# won't work
class Array(array.arr ay):
def __init__(self, typecode, initalizer=(), mine=None):
array.array.__i nit__(self, typecode, initializer)
self.mine = mine

However, array.array is a bit harder to subclass:

# should work
class Array(array.arr ay):
def __new__(cls, typecode, initializer=(), mine=None):
return array.array.__n ew__(cls, typecode, initializer)
def __init__(self, typecode, initializer=(), mine=None):
array.array.__i nit__(self, typecode, initializer)
self.mine = mine

See if you can get away by making the array an attribute of your class
instead.

Peter
Oct 4 '06 #4

Peter Otten wrote:
SpreadTooThin wrote:
If you are deriving a new class from another class,
that you must (I assume) know the initializer of the other class.

So in myClass

import array
class myClass(arrary. array):
def __init__(self, now here I need to put array's constructor
parameters..., then mine):
array.array.__i nit__(self, typecode[, initializer])
self.mine = mine

So I'm confused...
array has a typecode parameter and an optional initiializer...
So could you help me with the class construction here please?

Normally you would do

# won't work
class Array(array.arr ay):
def __init__(self, typecode, initalizer=(), mine=None):
array.array.__i nit__(self, typecode, initializer)
self.mine = mine

However, array.array is a bit harder to subclass:

# should work
class Array(array.arr ay):
def __new__(cls, typecode, initializer=(), mine=None):
return array.array.__n ew__(cls, typecode, initializer)
def __init__(self, typecode, initializer=(), mine=None):
array.array.__i nit__(self, typecode, initializer)
self.mine = mine

See if you can get away by making the array an attribute of your class
instead.
Thanks.
the =() syntax indicates what?
Just slightly off topic here but if Array had a bunch of initializers
of its own,
must all the 'optional' parameters be on the right.. ie the last
parameters?

Peter
Oct 4 '06 #5
SpreadTooThin wrote:
the =() syntax indicates what?
No special syntax, just an empty tuple as a default parameter.
In this case I could have used an empty list, too, but I thought I'd spare
you the dangers of mutable default values as explained here:

http://www.python.org/doc/faq/general/#id53
Just slightly off topic here but if Array had a bunch of initializers
of its own, must all the 'optional' parameters be on the right.. ie the
last parameters?
Yes.

Peter
Oct 4 '06 #6

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

Similar topics

21
2980
by: Chris Reedy | last post by:
For everyone - Apologies for the length of this message. If you don't want to look at the long example, you can skip to the end of the message. And for the Python gurus among you, if you can spare the time, I would appreciate any comments (including words like evil and disgusting, if you think they are applicable :-}) on the example here. Kenny -
4
334
by: ---- | last post by:
Here are my files (problem follows the code): -------------------------------------------------------------------------- // Group.h #ifndef GROUP_H #define GROUP_H class Group { public:
23
2522
by: Carter Smith | last post by:
http://www.icarusindie.com/Literature/ebooks/ Rather than advocating wasting money on expensive books for beginners, here's my collection of ebooks that have been made freely available on-line by their authors. There are lots of them out there but this selection cuts out the junk. If you know of any other good books that are freely available please post a link to them here and I'll consider adding them to the site.
39
2519
by: clintonG | last post by:
This is not about starting a fight but an observation that seems to be proving itself on its own merit and is therefore simply a point of conjecture. I did not get serious about writing software until I learned ASP/VBS (if that can be called writing software) as my focus was and remains for the most part developing for the web. Even though I have had a programming class in C which I somehow passed, JavaScript always gave me the heeby...
2
1470
by: Edd | last post by:
Hello all, Please consider: class Base { public: int pub; protected: int prot; private: int priv; };
17
2529
by: Student | last post by:
Hi All, I have an assignment for my Programming language project to create a compiler that takes a C++ file as input and translate it into the C file. Here I have to take care of inheritance and operator overloading and virtual functions. I mean it should not hamper the C++ meaning. In frank and simple terms i need to implement a small C++ compiler in C++, and i want the intermediate representation to be C. Please help me in this....
13
3244
by: Fao | last post by:
Hello, I am having some problems with inheritance. The compiler does not not return any error messages, but when I execute the program, it only allows me to enter the number, but nothing else happend. I think the problem may be in my input function or in the main function. If anyone out there can help me it woul be greatly appreciated. Here is the code: #include <iostream>
18
2329
by: bsruth | last post by:
I tried for an hour to find some reference to concrete information on why this particular inheritance implementation is a bad idea, but couldn't. So I'm sorry if this has been answered before. Here's the scenario: We have a base class with all virtual functions. We'll call this the Animal class. We then make two classes Fish and Bird that both inherit from Animal. In the program, we have a single array of Animal pointers that will...
3
1598
by: Zootal | last post by:
I have a question about the syntax involved in inheritance. I have a parent class, and a child class. When I create an instance of the class, I pass to it 3 parameters. Two of them are used by the child class, one by the parent class. I can do this: class Child { public: Child( int parm1, int parm2, int parm3) : Parent( parm3) {
0
8466
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8384
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8810
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8590
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8659
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7410
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6211
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2035
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.