Attack a sacred Python Cow
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sun Jul 27 04:13:53 EDT 2008
On Sun, 27 Jul 2008 10:23:06 +0800, Marcus.CM wrote:
> Well after reading some of these posts on "sacred python cow" on the
> "self" , i would generally feel that most programmers who started with
> C++/Java would find it odd.
You know, there are some programmers who haven't started with C++ or Java.
> And its true, i agree completely there
> should not be a need to put "self" into every single member function. If
> you were writing an application and one of your classes adds the same
> variable to each of its member function you would do away with it too.
Would I?
How would I do that here?
# untested
class FunnyNumber(int):
"""Silly class that acts like an integer, only one larger."""
def __add__(self, other):
return int(self)+1+other
def __mul__(self, other):
return (self+1)*other
def __sub__(self, other):
return int(self)+1-other
--
Steven
More information about the Python-list
mailing list