studying python
Sep. 5th, 2005 08:42 pmFunny, I can have an instance of class X, then add a method to that class, and the instance has the method. That's kind of great. But as well I can assign a method to that specific instance:
x = X('this is "x"')
X.g = lambda parameter: sys.stdout.write('X.g() called with parameter %s' % parameter)
x.g() will call X.g() and pass itself as a parameter.
Now
x.g = lambda parameter: sys.stdout.write('x.g() called with parameter %s' % parameter)
x.g() won't work; have to write x.g(x) to pass the instance.
Any logic here?
x = X('this is "x"')
X.g = lambda parameter: sys.stdout.write('X.g() called with parameter %s' % parameter)
x.g() will call X.g() and pass itself as a parameter.
Now
x.g = lambda parameter: sys.stdout.write('x.g() called with parameter %s' % parameter)
x.g() won't work; have to write x.g(x) to pass the instance.
Any logic here?