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

Multiple hierarchie and method overloading

Hi,


I have something like this:

Class A:
def A_Func(self, p_param):
.....
Class B:
def A_Func(self):
.....

Class C (A,B):
A.__init__(self)
B.__init__(self)

......

self.A_Func() #HERE I GET AN EXCEPTION "... takes at least 2 arguments (1
given).
I renamed A_Func(self) to fix that ... but is there a cleaner way around ?

Regards,

Philippe

Apr 25 '06 #1
7 948
Philippe Martin wrote:
I have something like this:

Class A:
def A_Func(self, p_param):
.....
Class B:
def A_Func(self):
.....

Class C (A,B):
A.__init__(self)
B.__init__(self)

.....

self.A_Func() #HERE I GET AN EXCEPTION "... takes at least 2 arguments (1
given).
I renamed A_Func(self) to fix that ... but is there a cleaner way around ?


When using multiple inheritence, the order of the base classes matters!
E.g.:

class A(object):
def f(self):
print 'in A.f()'
class B(object):
def f(self):
print 'in B.f()'
class X(A, B):
pass
class Y(B, A):
pass
x = X()
x.f() in A.f() y = Y()
y.f() in B.f()

If you want to call B.f() instead of A.f() for an X instance, you can
either rename B.f() like you've done, or do this:
B.f(x)

in B.f()

--Ben

Apr 25 '06 #2
In article <11**********************@v46g2000cwv.googlegroups .com>,
"Ben Cartwright" <be****@gmail.com> wrote:
Philippe Martin wrote:
I renamed A_Func(self) to fix that ... but is there a cleaner way around ?


When using multiple inheritence, the order of the base classes matters!


When you have to start worrying about complications like this, isn't
that a sign that you're taking the whole OO thing a little too seriously?

After all, technology is supposed to _solve_ problems, not create them.
If the complications of OO are making you lose sight of your original
problem, then maybe you should put them aside.
Apr 25 '06 #3
Philippe Martin wrote:
Hi,


I have something like this:

Class A:
def A_Func(self, p_param):
.....
Class B:
def A_Func(self):
.....

Class C (A,B):
A.__init__(self)
If that's really your code, you should have an exception right here.
Else, please post real code.

B.__init__(self)
.....

self.A_Func() #HERE I GET AN EXCEPTION "... takes at least 2 arguments (1
given).

I renamed A_Func(self) to fix that ... but is there a cleaner way around ?


Perhaps should you read these texts:

http://diveintopython.org/object_ori...g_classes.html
http://www.freenetpages.co.uk/hp/ala...d/tutclass.htm
http://docs.python.org/tut/node11.html
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Apr 25 '06 #4
Philippe Martin wrote:
Hi,

I have something like this:

Class A:
def A_Func(self, p_param):
.....
Class B:
def A_Func(self):
.....

Class C (A,B):
A.__init__(self)
B.__init__(self)

.....

self.A_Func() #HERE I GET AN EXCEPTION "... takes at least 2 arguments (1
given).
Ho, yes, also: A.A_Func() really takes 2 arguments (self, and p_param).
When called from an instance of A, the first argument (ie: self) will be
automagically feed with the instance itself - but you still have to pass
the second one.

I renamed A_Func(self) to fix that ... but is there a cleaner way around ?


Yes : passing the second argument.

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Apr 25 '06 #5
Lawrence D'Oliveiro wrote:
In article <11**********************@v46g2000cwv.googlegroups .com>,
"Ben Cartwright" <be****@gmail.com> wrote:

Philippe Martin wrote:

I renamed A_Func(self) to fix that ... but is there a cleaner way around ?


When using multiple inheritence, the order of the base classes matters!

When you have to start worrying about complications like this, isn't
that a sign that you're taking the whole OO thing a little too seriously?

After all, technology is supposed to _solve_ problems, not create them.
If the complications of OO are making you lose sight of your original
problem, then maybe you should put them aside.

def fun(arg1, arg2):
pass

fun()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: fun() takes exactly 2 arguments (0 given)

If the complication of functions are making you loose sight of your
original problem, then maybe you should put them aside ?-)
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Apr 25 '06 #6
Well, the whole point was to clean up my code:

Actually this is what I have:

Class A:
def A_Func(self, p_param):
.....
Class B:
def A_Func(self):
.....

Class C (A,B):
A.__init__(self)
B.__init__(self)

Class D (A,B):
A.__init__(self)
B.__init__(self)
Where A is a wxWidget class and B a "Common/utility" class which I wanted to
factorize (and yes, inheritance was not mandatory here, just simpler)

My common class does have an A_Func(self) while wxWidget an A_Func(self,
p_param) ==> I actually got the error calling A_Func(self) as it was
checked against A_Func(self, p_param).

Regards,

Philippe



Lawrence D'Oliveiro wrote:
In article <11**********************@v46g2000cwv.googlegroups .com>,
"Ben Cartwright" <be****@gmail.com> wrote:
Philippe Martin wrote:
I renamed A_Func(self) to fix that ... but is there a cleaner way around
?


When using multiple inheritence, the order of the base classes matters!


When you have to start worrying about complications like this, isn't
that a sign that you're taking the whole OO thing a little too seriously?

After all, technology is supposed to _solve_ problems, not create them.
If the complications of OO are making you lose sight of your original
problem, then maybe you should put them aside.


Apr 25 '06 #7
Thanks,

I'll try that.

Philippe
Ben Cartwright wrote:
Philippe Martin wrote:
I have something like this:

Class A:
def A_Func(self, p_param):
.....
Class B:
def A_Func(self):
.....

Class C (A,B):
A.__init__(self)
B.__init__(self)

.....

self.A_Func() #HERE I GET AN EXCEPTION "... takes at least 2
arguments (1
given).
I renamed A_Func(self) to fix that ... but is there a cleaner way around
?


When using multiple inheritence, the order of the base classes matters!
E.g.:

class A(object):
def f(self):
print 'in A.f()'
class B(object):
def f(self):
print 'in B.f()'
class X(A, B):
pass
class Y(B, A):
pass
>>> x = X()
>>> x.f() in A.f() >>> y = Y()
>>> y.f() in B.f()

If you want to call B.f() instead of A.f() for an X instance, you can
either rename B.f() like you've done, or do this:
>>> B.f(x)

in B.f()

--Ben


Apr 25 '06 #8

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

Similar topics

2
by: Piet | last post by:
Hello, I have a short question about sizers and how they work when I have a frame or panel with a complex sizer hierarchie. When creating a new sizer which sits itself in its parent sizer, should...
5
by: alex | last post by:
Hi, it is possible to define multiple initialization methods so that the method is used that fits? I am thinking of something like this: def __init__(self, par1, par2): self.init(par1,...
4
by: John Smith | last post by:
can we overload a javascript function with different argument? example: function a(a){} function a(a,b){}
18
by: Daniel Gustafsson | last post by:
Hi there, hmm, I've just started with C# and I'm experimenting with method overloading. It seems like it's not possible to override method using return types, only parameters. Is that by design,...
9
by: Ryan Taylor | last post by:
Hello. I am trying to overload a method so that I have four possible working copies. The only difference between the four methods is what to search by and in what manner to return the results....
2
by: Iter | last post by:
Hi Guys, In my company, we have java application which is runing in unix platform, and we have web service application build by microsoft .net runing in IIS in microsoft windows 2000 platform....
11
by: placid | last post by:
Hi all, Is it possible to be able to do the following in Python? class Test: def __init__(self): pass def puts(self, str): print str
5
by: Andreas Schmitt | last post by:
I have a problem here. I've read a book about C# already and got the basics of how the language handles polymorphism I think but I ran into a problem here that I simply never even thought of as a...
10
by: Matthew | last post by:
Am I correct in thinking there is no method/function overloading of any kind in any version of PHP? Thanks, Matthew
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...
0
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...
0
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...

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.