'Learning Python' by Lutz and Ascher (excellent book by the way)
explains that a subclass can call its superclass constructor as
follows:
class Super:
def method(self):
# do stuff
class Extender(Super) :
def method(self):
Super.method(se lf) # call the method in super
# do more stuff - additional stuff here
I'm trying to use this for a superclass called 'component' in the
constructor. I have different types of component (let's say for
arguments sake resistor, capacitor etc). When I instantiate a new
resistor, say, I want the constructor to call the constructor within
the component superclass, and then add some resistor-specific stuff.
Now, this is fine using the above code. Where I'm struggling is with
argument passing. The following, for example, doesn't seem to work:
class Super:
def __init__(self, **kargs):
self.data = kargs
class Extender(Super) :
def __init__(self, **kargs):
Super.__init__( self, kargs) # call the constructor method in Super
# do additional extender-specific stuff here
What am I doing wrong? I get:
TypeError: __init__() takes exactly 1 argument (2 given)
WARNING: Failure executing file: <main.py>
Dave 4 2905 da*******@f2s.c om wrote:
'Learning Python' by Lutz and Ascher (excellent book by the way)
explains that a subclass can call its superclass constructor as
follows:
(snip)
>
Now, this is fine using the above code. Where I'm struggling is with
argument passing. The following, for example, doesn't seem to work:
class Super:
def __init__(self, **kargs):
self.data = kargs
class Extender(Super) :
def __init__(self, **kargs):
Super.__init__( self, kargs) # call the constructor method in Super
# do additional extender-specific stuff here
What am I doing wrong? I get:
TypeError: __init__() takes exactly 1 argument (2 given)
WARNING: Failure executing file: <main.py>
class Super(object):
def __init__(self, **kwargs):
self.data = kwargs
class Extender(Super) :
def __init__(self, **kwargs):
Super.__init__( self, **kwargs)
# do additional extender-specific stuff here
HTH
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
On Wed, Jul 26, 2006 at 09:21:10AM -0700, da*******@f2s.c om wrote:
'Learning Python' by Lutz and Ascher (excellent book by the way)
explains that a subclass can call its superclass constructor as
follows:
class Super:
def method(self):
# do stuff
class Extender(Super) :
def method(self):
Super.method(se lf) # call the method in super
# do more stuff - additional stuff here
I'm trying to use this for a superclass called 'component' in the
constructor. I have different types of component (let's say for
arguments sake resistor, capacitor etc). When I instantiate a new
resistor, say, I want the constructor to call the constructor within
the component superclass, and then add some resistor-specific stuff.
Now, this is fine using the above code. Where I'm struggling is with
argument passing. The following, for example, doesn't seem to work:
class Super:
def __init__(self, **kargs):
self.data = kargs
class Extender(Super) :
def __init__(self, **kargs):
Super.__init__( self, kargs) # call the constructor method in Super
You mean
Super.__init__( self, **kargs)
Note the ** in the call the parent's init method.
# do additional extender-specific stuff here
What am I doing wrong? I get:
TypeError: __init__() takes exactly 1 argument (2 given)
WARNING: Failure executing file: <main.py>
Dave
-- http://mail.python.org/mailman/listinfo/python-list da*******@f2s.c om wrote:
'Learning Python' by Lutz and Ascher (excellent book by the way)
explains that a subclass can call its superclass constructor as
follows:
class Super:
def method(self):
# do stuff
class Extender(Super) :
def method(self):
Super.method(se lf) # call the method in super
# do more stuff - additional stuff here
I'm trying to use this for a superclass called 'component' in the
constructor. I have different types of component (let's say for
arguments sake resistor, capacitor etc). When I instantiate a new
resistor, say, I want the constructor to call the constructor within
the component superclass, and then add some resistor-specific stuff.
Now, this is fine using the above code. Where I'm struggling is with
argument passing. The following, for example, doesn't seem to work:
class Super:
def __init__(self, **kargs):
self.data = kargs
class Extender(Super) :
def __init__(self, **kargs):
Super.__init__( self, kargs) # call the constructor method in Super
# do additional extender-specific stuff here
What am I doing wrong? I get:
TypeError: __init__() takes exactly 1 argument (2 given)
WARNING: Failure executing file: <main.py>
Dave
Try this:
class Extender(Super) :
def __init__(self, **kargs):
Super.__init__( self, **kargs) # call the constructor method in
Super
(add two asterisks to the call.)
Observe, the following script:
def a(*a, **b):
return a, b
print a(**{'arg':2})
print a(arg=2)
print a({'arg':2})
# Prints:
((), {'arg': 2})
((), {'arg': 2})
(({'arg': 2},), {})
HTH,
~Simon
"Chris Lambacher" <ch***@kateandc hris.netwrote in message
news:ma******** *************** *************** *@python.org...
On Wed, Jul 26, 2006 at 09:21:10AM -0700, da*******@f2s.c om wrote:
'Learning Python' by Lutz and Ascher (excellent book by the way)
explains that a subclass can call its superclass constructor as
follows:
class Super:
def method(self):
# do stuff
class Extender(Super) :
def method(self):
Super.method(se lf) # call the method in super
# do more stuff - additional stuff here
With new-style classes (where Super inherits from object), I think the
preferred style is now:
super(Extender, self).__init__( **kwargs)
Instead of
Super.__init__( self,**kwargs)
class Super(object):
def __init__(self, **kargs):
print kargs
self.data = kargs
class Extender(Super) :
def __init__(self, **kargs):
#~ Super.__init__( self, **kargs) # call the constructor method in
Super
super(Extender, self).__init__( **kargs)
e = Extender(a=123)
prints:
{'a': 123}
-- Paul This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stanley Sinclair |
last post by:
Bear with me. I am being very calm; took a Valium. I have waited two
weeks to write this, because every time I wrote it before the message
was, at best, nasty.
I need to use the services of NET SEARCH EXTENDER. This is the first
time in over five years of IBM (DB2) developing that I need this.
I don't know how to do it. (Db2 v8.1.2, Windows) I see that I must
deal with indexes, with cache, with other stuff.
|
by: Belinda |
last post by:
Hi. I am just getting started with DB2's spatial extender and could
really use some help. Pointers to good docs or examples are welcome.
I am using DB2 version 8 on Sun. I have a database of genomic data
and believe the spatial extender will help in querying. I have to do
intersections, subtractions, proximity, etc of ranges in the
chromosomes. The database and even some tables include data on all
chromosomes of several species. I am...
|
by: JezB |
last post by:
I've written an extender provider for ASP.NET windows forms controls and web
controls. My windows forms solution works fine, but my ASP.NET solution does
not persist any property values I enter via the visual studio property grid.
Upon examination of the code within InitializeComponent I can see why : no
code is automatically embedded to call the Set method of my property.
Anyone have any ideas why ? Is there any solution ?
|
by: A.M-SG |
last post by:
Hi,
I am developing a SOAP extender and I need to store some session information
at BeforeSerialize ProcessMessage event, so at the AfterDeserialize
ProcessMessage event I know which call I am dealing with.
What would be the best way for storing some session information during
ProcessMessage method call?
|
by: Brad |
last post by:
To DB2 Personal Developer Edition GIS users:
How do I acquire a spatial extender license key for the DB2 PDE? I
expected to be able to use it right out of the box.
Brad
| |
by: William Youngman |
last post by:
I have a gridview displaying data and would like to use the AJAX dropdown extender so that when the user clicks on a record a dropdown menu will display providing the user with a menu of selections to choose from (yes much like the SharePoint 2007 dropdown menu).
I'm having problems dynamically binding the 'TargetControlID' property of the extender control to the record label in the gridview.
What I'm doing is -
The label's text is the...
|
by: William Youngman |
last post by:
We are developing an application that presents data to the user in a gridview and we are using the dropdown extender to give the user a SharePoint 2007 type dropdown menu attached to the cells of a given column. We are also using another dropdown menu that the user can use to select data using another quesry using the SelectedIndex change method. Upon initial page load everything works fine and the user is presented with a SharePoint type menu....
|
by: =?Utf-8?B?UGF1bA==?= |
last post by:
Hi I am using a popup control extender (ajax control) and have placed a .net
button on the panel that is displayed when the hyperlink is selected that is
the target control of the popup extender. When I double click on the button
in design view (it creates the method protected void Button1_Click(object
sender, EventArgs e)
{
}
but when I run the app and click on the button I get a runtime error
this._postBackSettings.async' is null or...
|
by: gagandeepgupta16 |
last post by:
Hi
I am working on an entry form using validation controls in ASP.NET.
I have two controls which requires custom validators, no issue in using plain custom validators.
But when i am using Validation Callout Extender with the custom validators its not working properly.
here is the link where i got solution for one custom validator with validation callout extender :-
http://www.junnark.com/Articles/Article0001.aspx
I searched a lot but...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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...
|
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,...
|
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...
|
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...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |