472,353 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

howto overload with a NOP (empty statement)

How should I overload / disable a method ?
In the example below I have defined the class "Power_Supply", derived
from baseclass "device".
The baseclass has a method "execute", which will be implemented in most
derived classes, but not in all.
Now apparently it's not allowed to overload a method with an empty
statement.
I could write a nonsense dummy statement, like "A= 3", but isn't there
another way ?

thanks, Stef Mientki

class device:
def execute (self):
print 'execute not yet implemented for', self.Name
class Power_Supply (device):
def execute (self): ;
Jan 6 '07 #1
5 4225
class Power_Supply (device):
def execute (self):
pass

Stef Mientki wrote:
How should I overload / disable a method ?
In the example below I have defined the class "Power_Supply", derived
from baseclass "device".
The baseclass has a method "execute", which will be implemented in most
derived classes, but not in all.
Now apparently it's not allowed to overload a method with an empty
statement.
I could write a nonsense dummy statement, like "A= 3", but isn't there
another way ?

thanks, Stef Mientki

class device:
def execute (self):
print 'execute not yet implemented for', self.Name
class Power_Supply (device):
def execute (self): ;
Jan 6 '07 #2
Stef Mientki wrote:
How should I overload / disable a method ?
In the example below I have defined the class "Power_Supply", derived
from baseclass "device".
The baseclass has a method "execute", which will be implemented in most
derived classes, but not in all.
Now apparently it's not allowed to overload a method with an empty
statement.
I could write a nonsense dummy statement, like "A= 3", but isn't there
another way ?
pass

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Jan 6 '07 #3
Stef Mientki a écrit :
How should I overload / disable a method ?
In the example below I have defined the class "Power_Supply", derived
from baseclass "device".
<off>
Naming conventions are to use CamelCase for class names. So it would be
better to name your classes 'PowerSupply' (no '_') and 'Device'. You're
of course free to use whatever naming convention you want, including no
convention at all, but Python relies *a lot* on naming conventions...
</off>
The baseclass has a method "execute",
<off>
Do you know that Python let you define your own 'callable' objects ?

class SomeCallable(object):
def __init__(self, name):
self.name = name
def __call__(self):
print "wow, %s has been called" % self.name

foo = SomeCallable('foo')
foo()

This may or not make sens in the context of your application, but
whenever you find yourself naming a method 'execute', it might be worth
asking yourself if the object should in fact be a callable...
</off>
which will be implemented in most
derived classes, but not in all.

Now apparently it's not allowed to overload a method with an empty
statement.
I could write a nonsense dummy statement, like "A= 3", but isn't there
another way ?
the 'pass' statement

def noop():
pass
thanks, Stef Mientki

class device:
def execute (self):
print 'execute not yet implemented for', self.Name
The usual idiom for 'pure virtual methods' is to raise a
NotImplementedError. Now if it's ok for a subclass to implement the
method as a no-op, why not just implement it as a no-op in the base
class itself ?
Jan 6 '07 #4
Stef Mientki wrote:
How should I overload / disable a method ?
In the example below I have defined the class "Power_Supply", derived
from baseclass "device".
The baseclass has a method "execute", which will be implemented in most
derived classes, but not in all.
Now apparently it's not allowed to overload a method with an empty
statement.
I could write a nonsense dummy statement, like "A= 3", but isn't there
another way ?

thanks, Stef Mientki

class device:
def execute (self):
print 'execute not yet implemented for', self.Name
class Power_Supply (device):
def execute (self): ;

class device:
def execute (self):
raise NotImplementedError('virtual: should do this and that')

This NotImplementedError virtual method scheme will also be detected by pychecker in order to warn correctly: that classes of actual instances have to override all open virtuals.
Robert
Jan 6 '07 #5
Bruno Desthuilliers kirjoitti:
Stef Mientki a écrit :
>How should I overload / disable a method ?
In the example below I have defined the class "Power_Supply", derived
from baseclass "device".

<off>
Naming conventions are to use CamelCase for class names. So it would be
better to name your classes 'PowerSupply' (no '_') and 'Device'. You're
of course free to use whatever naming convention you want, including no
convention at all, but Python relies *a lot* on naming conventions...
</off>
Continuing with the style and idioms issues...

1. Don't leave a space between a function/method/class name and the
opening parenthesis, i.e. instead of:
def execute (self):
use:
def execute(self):

2. It seems to me that you indent your code with 2 spaces. If I'm wrong,
please ignore me. Otherwise: always use 4 spaces when indenting with spaces.

Following these and the numerous other guidelines (see
htpp://www.python.org/dev/peps/pep-0008/ for example) on Python style
you'll be making yourself and others a favor. When these coding
guidelines become your habit, it will be easier for you to read the code
of other Pythoners. This is important because a large part of learning
consists of reading the code of others.

And also vice versa: when you show your code to others, it will be
easier for them to concentrate on your problem when the idiosyncrasy of
your code is not there to hinder.

Cheers,
Jussi
Jan 6 '07 #6

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

Similar topics

4
by: Michael T. Peterson | last post by:
I am unable to figure out how to overload the '==' operator. The code below( cc'd it from an example on the net) doesn't compile: bool operator==...
7
by: Sean | last post by:
Can someone help me see why the following "operator=" overloading doesn't work under g++? and the error message is copied here. I see no reason the...
10
by: Benny Raymond | last post by:
I'm trying to change the way a treeview works just a bit, i'm pretty new to C# and now i'm running into overloading. I tried the following code...
2
by: sparks | last post by:
I had the bright idea of using if/else to call different constructors based on a web form and what the user entered. ...
1
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm...
4
by: davearkley | last post by:
I've recently 'discover' the wonders of custom attributes and reflection. There's one aspect that has stumping me and I've been unable to find...
7
by: =?Utf-8?B?QVRT?= | last post by:
HOWTO Make CStr for JavaScript on ASP w/ Request.Form and QueryString In ASP, Request.Form and Request.QueryString return objects that do not...
5
by: phiefer3 | last post by:
I'm currently a student, but this problem isn't directly related to what I have to do on an assignment. It's just a problem I've had with some...
11
by: EricGoogle | last post by:
Hello All, I am trying to figure out a how to get a variable's name from code. Ex: var MYVAR = 3; alert( ????? ); OUTPUT: "MYVAR"
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.