Sep. 5th, 2005

juan_gandhi: (Default)
Funny, 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?

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

November 2025

S M T W T F S
       1
23456 7 8
9 1011 12 1314 15
16171819 20 2122
23 24 2526272829
30      

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Nov. 27th, 2025 12:38 am
Powered by Dreamwidth Studios