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

overwriting method in baseclass

Hello!

I am using a library (= code of so else) within Python. Somewhere in this
library there is:

class foo:
def baa(self, parameters):
print "something"
self.baazanan(some other parameters)
class mirbo(foo):
def baazanan(self, lalala):
print "heylo tada"

class fujiko(foo):
def baazanan(self, ltara):
print "sing a song with me"
.....
now I want to change the common baa-method. so that

def baa(self, parameters):
print "soemthing special"
self.baazanan(some other parameters)

Of course, I use a Python- and GPL-Licence compatible library, I can
change the source of foo, and use my changed library.

But someday, it happened before, there will be an update by the publisher
to that library.... and I have to do all again.

So, what is the most elegant solution to administer these changes?

Harald
Jul 18 '05 #1
5 1854
Harald Massa wrote:
Hello!

I am using a library (= code of so else) within Python. Somewhere in this
library there is:

class foo:
def baa(self, parameters):
print "something"
self.baazanan(some other parameters)
class mirbo(foo):
def baazanan(self, lalala):
print "heylo tada"

class fujiko(foo):
def baazanan(self, ltara):
print "sing a song with me"
....
now I want to change the common baa-method. so that

def baa(self, parameters):
print "soemthing special"
self.baazanan(some other parameters)

Of course, I use a Python- and GPL-Licence compatible library, I can
change the source of foo, and use my changed library.

But someday, it happened before, there will be an update by the publisher
to that library.... and I have to do all again.

So, what is the most elegant solution to administer these changes?


Given these classes:

py> class foo:
.... def baa(self):
.... print "something"
.... self.baazanan()
....
py> class mirbo(foo):
.... def baazanan(self):
.... print "heylo tada"
....
py> class fujiko(foo):
.... def baazanan(self):
.... print "sing a song with me"
....

You should be able to redefine the method and assign it to the foo class:

py> def new_baa(self):
.... print "soemthing special"
.... self.baazanan()
....
py> foo.baa = new_baa

Then any instances created after this assignment should use the new baa
method you defined:

py> mirbo().baa()
soemthing special
heylo tada
py> fujiko().baa()
soemthing special
sing a song with me

You also might bring up this point to the maintainer of the library --
if they know your intents, they can make this easier for you...

STeVe
Jul 18 '05 #2
Harald Massa wrote:
Hello!

I am using a library (= code of so else) within Python. Somewhere in this
library there is:
(snip)

now I want to change the common baa-method. so that
(snip)
Of course, I use a Python- and GPL-Licence compatible library, I can
change the source of foo, and use my changed library.

But someday, it happened before, there will be an update by the publisher
to that library.... and I have to do all again.

So, what is the most elegant solution to administer these changes?


<ot>
Use a version control system (svn is quite fine...).
</ot>

--
bruno desthuilliers
ruby -e "print 'o****@xiludom.gro'.split('@').collect{|p|
p.split('.').collect{|w| w.reverse}.join('.')}.join('@')"
--
Jul 18 '05 #3
bruno modulix <on***@xiludom.gro> wrote in
So, what is the most elegant solution to administer these changes?


<ot>
Use a version control system (svn is quite fine...).
</ot>


Thanks for that recommendation, I really do use subversion for some time.
But how can I use it to solve this problem? I do changes to the common
baseclass which is OUTSIDE my development. I quite correctly assume that
the developers of the classlib also use Subversion, alas, having no public
access.

So HOW can SVN be of any use for THIS prob?

Harald
Jul 18 '05 #4
In <Xn**********************************@195.20.224.1 16>, Harald Massa
wrote:
Thanks for that recommendation, I really do use subversion for some time.
But how can I use it to solve this problem? I do changes to the common
baseclass which is OUTSIDE my development. I quite correctly assume that
the developers of the classlib also use Subversion, alas, having no public
access.

So HOW can SVN be of any use for THIS prob?


Take a look at the Subversion documentation (the "book") and search for
`Vendor branches`.

First paragraph of that section:

As is especially the case when developing software, the data that you
maintain under version control is often closely related to, or perhaps
dependent upon, someone else's data. Generally, the needs of your
project will dictate that you stay as up-to-date as possible with the
data provided by that external entity without sacrificing the stability
of your own project. [...]

The section deals specifically with the situation how to manage 3rd party
source code with subversion which you want to update from time to time and
even apply some modifications.

Ciao,
Marc 'BlackJack' Rintsch
Jul 18 '05 #5
marc,
So HOW can SVN be of any use for THIS prob?
Take a look at the Subversion documentation (the "book") and search
for `Vendor branches`.

[...] The section deals specifically with the situation how to manage 3rd
party source code with subversion which you want to update from time
to time and even apply some modifications.


thank you very much for pointing this out! I did not even dare to hope to
find sth. of this kind with a rcs for MY software.

So I did not even start searching.

Thank you,

Harald
Jul 18 '05 #6

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

Similar topics

10
by: John Brock | last post by:
I have a base class with several derived classes (I'm writing in VB.NET). I want each derived class to have a unique class ID (a String), and I want the derived classes to inherit from the base...
4
by: Zeng | last post by:
I often run into situation where I would like to have a method such as that has derived behavior similar to destructors in c++, is that possible? public BaseClass { private int m_dataInBase;...
10
by: Peter Oliphant | last post by:
Is there a way of defining a method in a base class such that derived classes will call their own version, EVEN if the derived instance is referred to by a pointer to the base class? Note that the...
0
by: cnSoftware | last post by:
I have two classes as below: public class BaseClass { public BaseClass() { } public BaseClass(string name) { this._name = name; }
1
by: Paul_P | last post by:
Hello all, We are using Managed and Unmanaged C++ code, on Windows XP SP2, VC++ .NET 2003. In the SubClass we are trying to override a virtual method of the BaseClass that has an unmanaged type...
6
by: Mirek Endys | last post by:
Hello all, another problem im solving right now. I badly need to get typeof object that called static method in base classe. I did it by parameter in method Load, but i thing there should be...
2
by: Bit byte | last post by:
I have a base (abstract) class with a public method foo delared as: virtual BaseClass* foo(..)=0; I wnat to derive two classes A and B from Baseclass so that I return a pointer for A and B...
6
by: wingphil | last post by:
Hi there, I have a shared method in a base class, and I need to know which subclass it has been called from. So for example Public Mustinherit Class BaseClass Public Shared Sub SharedMethod...
5
by: none | last post by:
I'd like to create a new static property in a class "hiding" the property present in a base class. Since this needs to happen at runtime I tried doing this via DynamicMethod. But obviously the...
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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,...
0
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...
0
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...

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.