Hi,
Could anybody help me with a sample code for function overidding.
Thanks & Regards
PSB
3 1000
Hi,
Could anybody help me with a sample code for function overidding.
Thanks & Regards
PSB
Just like you'd expect: - class SuperClass(object):
-
def func1(self):
-
print 1234
-
-
class SubClass(SuperClass):
-
def func1(self):
-
print 5678
-
SuperClass.func1(self)
-
-
sc = SubClass()
-
sc.func1()
Just like you'd expect: - class SuperClass(object):
-
def func1(self):
-
print 1234
-
-
class SubClass(SuperClass):
-
def func1(self):
-
print 5678
-
SuperClass.func1(self)
-
-
sc = SubClass()
-
sc.func1()
Hi,
Thanks for the example.
In case of C++ we have a Pointer concept and we can play with Base Class Object and Derived class objects to access the common methods or overriden methods thru thier Objects.Is it possible in Python to get the same functionality by assigning the derive class object to the base class and get access to the methods of the derived classes.As shown in the below example.If possible could you please help me in getting the sample code.
Example in C++ :
class A {
virtual void f() { cout << "Class A" << endl; }
};
class B:public A {
void f(int) { cout << "Class B" << endl; }
};
class C:public B {
void f() { cout << "Class C" << endl; }
};
int main() {
B b; C c;
A* pa1 = &b;
A* pa2 = &c;
// b.f();
pa1->f();
pa2->f();
}
The following is the output of the above example:
Class A
Class C
Regards
PSB
bvdet 2,851
Expert Mod 2GB
In this case, BasisTransToGlobal() is based on Plane3D which is based on object. BasisTransToGlobal() inhehits all of Plane3d()'s methods. Plane3D() overloaded __repr__ is overridden. - class BasisTransToGlobal(Plane3D):
-
-
def __init__(self, vN, vA, vB, vR=Point(0,0,0)):
-
self.vN = vN
-
self.vA = vA
-
self.vB = vB
-
self.vR = vR
-
# local basis aligned with plane defined
-
Plane3D.__init__(self, vN, vA, vB)
-
-
if chk_type([vR, ]):
-
-
if self.N_len > 0.0:
-
-
# Unit vector normal to defined plane, local basis 'Z'
-
self.N = self.N_uv
-
-
# Unit vector between vN and vA, local basis 'X'
-
self.A = self.d0
-
-
# Unit cross product vector, local basis 'Y'
-
self.B = self.cross_product(self.N, self.A)
-
-
# global coordinate vector
-
self.R = self.translate(vR.x, vR.y, vR.z) + vN
-
-
else:
-
Warning("The points are collinear ***INVALID***")
-
self.R = None
-
else:
-
raise TypeError, "Arguments must be <type 'point'>"
-
-
def translate(self, X, Y, Z):
-
....................................................................................
-
# global coordinate vector with respect to local basis origin
-
return Point(R1.x*M, R1.y*M, R1.z*M)
-
-
def __repr__(self):
-
return 'BasisTransToGlobal(Point(%s), Point(%s), Point(%s), Point(%s))' % (self.vN, self.vA, self.vB, self.vR)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Michael Foord |
last post by:
#!/usr/bin/python -u
# 15-09-04
# v1.0.0
# auth_example.py
# A simple script manually demonstrating basic authentication.
# Copyright Michael Foord
# Free to use, modify and relicense.
#...
|
by: Ville Vainio |
last post by:
Just posting this for the sake of google:
Like everyone else, I figured it's time to start using the 'logging'
module.
I typically want to dump "info" level (and up) log information to...
|
by: relaxedrob |
last post by:
Hi All!
I ran the following w3c example through my WSDL parser (SOA Editor
from Cape Clear):
http://www.w3.org/TR/wsdl#_rpcexample
It told me that there were a bunch of erros about no...
|
by: Bo Xu |
last post by:
Object of Combination
By Bo Xu
Introduction
A combination of n things, taken s at a time, often referred as an
s-combination out of n, is a way to select a subset of size s from a
given set of...
|
by: Xah Lee |
last post by:
Python Doc Problem Example: gzip
Xah Lee, 20050831
Today i need to use Python to compress/decompress gzip files. Since
i've read the official Python tutorial 8 months ago, have spent 30...
|
by: ajikoe |
last post by:
Hello,
I used Visual C# Standard Edition.
I want to comment my program using xml commentary method,
I don't know why if I use value and example tag, it is not working / showed in the html...
|
by: cj |
last post by:
Lets just take this example I'm looking at now. I'm looking at the help
screen titled .NET Framework Class Library FolderBrowserDialog Class
. It gives an example at the bottom that begins with:...
|
by: Scott M. |
last post by:
Where will code that is preceded with:
/// <example>
/// some comments
/// </example>
actually show up?
I can see my <summaryand <remarkscode showing up in the code comment
pages and in...
|
by: meltedown |
last post by:
This is supposed ot be an example:
http://www.ajaxtutorial.net/index.php/2006/11/30/simple-ajax-using-prototype-part-2/
It says :
This example is probably the simplest example you will ever...
|
by: Guy Macon |
last post by:
While I agree with the sentiment, the oringinal title on this thread
("OT: Specially for , why you should always use example.com
for obfuscating domains") is wrong. There are other reserved domain...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
|
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,...
| |