Hi all~
I met problem when trying passing keyword arguments to derived class. my goal is to pass all keyword arguments to taht derived class as they did for superclass, but the result was not exactly what i want. below is my code:
class A:
def __init__(self, *args, **kw):
print args
print kw
print
class B(A):
def __init__(self, *args, **kw):
A.__init__(self, args, kw=kw)
a = A("a?", a_pro="a!")
b = B("b?", b_pro="b!")
here is the output:
('a?', )
{'a_pro':'a!'}
(('b?', ), ) # I want to get simply ('b?', ) here
{'kw':{'b_pro':'b!'}} # Here should also be ('b_pro':'b!')
any help ???
---------------------------------
Do you Yahoo!?
Free Pop-Up Blocker - Get it now 3 1729
On Thu, 25 Dec 2003 03:36:16 -0800 (PST), black <qu********@yahoo.com>
wrote: class A: def __init__(self, *args, **kw): print args print kw print class B(A): def __init__(self, *args, **kw): A.__init__(self, args, kw=kw) a = A("a?", a_pro="a!") b = B("b?", b_pro="b!")
here is the output:
('a?', ) {'a_pro':'a!'}
(('b?', ), ) # I want to get simply ('b?', ) here {'kw':{'b_pro':'b!'}} # Here should also be ('b_pro':'b!')
any help ???
I used Python 2.3.3. What is your version? class A:
def __init__(self, *args, **kw):
print args
print kw
print
class B(A):
def __init(self, *args, **kw):
A.__init__(selg,arg,kw)
a = A("a?", apro="a!")
('a?',)
{'apro': 'a!'}
b = B("b?", bpro="b!")
('b?',)
{'bpro': 'b!'}
--
JZ
On Thu, 25 Dec 2003 03:36:16 -0800 (PST), black <qu********@yahoo.com>
wrote: class A: def __init__(self, *args, **kw): print args print kw print class B(A): def __init__(self, *args, **kw): A.__init__(self, args, kw=kw) a = A("a?", a_pro="a!") b = B("b?", b_pro="b!")
here is the output:
('a?', ) {'a_pro':'a!'}
(('b?', ), ) # I want to get simply ('b?', ) here {'kw':{'b_pro':'b!'}} # Here should also be ('b_pro':'b!')
any help ???
I used Python 2.3.3. What is your version? class A:
def __init__(self, *args, **kw):
print args
print kw
print
class B(A):
def __init(self, *args, **kw):
A.__init__(self,arg,kw)
a = A("a?", apro="a!")
('a?',)
{'apro': 'a!'}
b = B("b?", bpro="b!")
('b?',)
{'bpro': 'b!'}
--
JZ
black wrote: ... class A: def __init__(self, *args, **kw): print args print kw print class B(A): def __init__(self, *args, **kw): A.__init__(self, args, kw=kw)
class C(A):
def __init__(self, *args, **kw):
A.__init__(self, *args, **kw) a = A("a?", a_pro="a!") b = B("b?", b_pro="b!")
c = C("c?", c_pro="c!")
Suggestion:
Really use the standard python convention of 4 characters per indent.
We promise not to charge you for extra spaces. This code was a trifle
harder to cut out of the message and paste into idle to replicate. It
also does help in reading code to trust there are no subtle indents.
-Scott David Daniels Sc***********@Acm.Org This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Shao Zhang |
last post by:
Hi,
I am not sure if the virtual keyword for the derived classes are
required given
that the base class already declares it virtual.
class A
{
public:
virtual ~A();
|
by: Daniel Schüle |
last post by:
Hello Ng,
I was playing around with pymedia module
and I succeeded when I used complementation
instead of inheritance .. but then I was
forced to wrap simple methods of sound.Output
like...
|
by: Daniel Kay |
last post by:
Hi Folks!
Everytime I work with virtual and pure virtual methods I ask myself if
there is a difference between class B and class C (see below). Is it
redundant to repeat the virtual keyword in a...
|
by: Zeng |
last post by:
Would somebody know when we should seal a class? Shouldn't all classes be
open up for inheritance?
Thanks!
|
by: Mark Broadbent |
last post by:
Oh yes its that chestnut again!
Ive gone over the following
(http://www.yoda.arachsys.com/csharp/faq/ -thanks Jon!) again regarding this
subject and performed a few of my own tests.
I have two...
|
by: flat_ross |
last post by:
For anyone who is just getting into VB.NET and/or is starting to work
with inheritance I would like to point out a potential pitfall. We
found this confusion recently when code-reviewing an...
|
by: Ant |
last post by:
HI, I'm using the protected keyword in a class to make a method accessible to
a child that inherits from it so as to be able to call the protected method
from the child class.
I can't seem to be...
|
by: jmborr |
last post by:
I need something like this:
1: superfoo( non-keyword-args, keyword-args, methodname, *kargs,
*kwargs):
2: """non-keyword-args and keyword-args are arguments that
3: apply to...
|
by: raylopez99 |
last post by:
Keywords: scope resolution, passing classes between parent and child
forms, parameter constructor method, normal constructor, default
constructor, forward reference, sharing classes between forms....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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,...
|
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,...
|
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...
| |