|
John recent posts about Python finally made me install and play with it.
When using it for the first time, two small Ingo-shaped beings (one sporting a devilish red glow - the other colored in divine white) popped up on my right and my left shoulder. One of them is still convincing me that this might actually be a good idea:
class Foo:
def Add (self, x, y):
return x+y
calc = Foo()
print calc.Add(1,2) # 3
Foo.Square = lambda self , x : x**2
print calc.Square(4) # 16
calc.Add = lambda x, y : x - y
print calc.Add(1,2) # -1
Foo.Add = lambda self, x, y : x + 1
calc2 = Foo()
print calc.Add(1,2) # -1
print calc2.Add(1,2) # 2
If you are a Python non-user, please look closely at the last two lines and also keep in mind that neither -1 nor 2 would be what you expected of class Foo's Add() method. Interesting, indeed. (Red still tried to convince me ("but think about the possibilitiiiiiieeeees ....") when he received a fatal blow from White.)
|