Hans Nowak is wondering about code blocks in Python. While Python's anonymous (lambda) functions are fairly awkward, Python does do a kind of "Currying" over self
. The following code shows the simpler mechanism Hans is looking for...
Jython 2.1 on java1.4.1_01 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> class FooBar:
... def foo(self):
... print self
... print "OK?"
...
>>> fb = FooBar()
>>> fb.foo()
__main__.FooBar instance at 17493979
OK?
>>> fb2 = FooBar()
>>> fb2
__main__.FooBar instance at 24940415
>>> fb2.foo()
__main__.FooBar instance at 24940415
OK?
>> fb2.foo()
__main__.FooBar instance at 24940415
OK?
>>> fb.foo
method FooBar.foo of FooBar instance at 17493979
>>> fb2.foo
method FooBar.foo of FooBar instance at 24940415
>>>
4 comments:
i don't understand ... nothing ...
lost me too...
-jl
To catch the grasshopper you must first be the grasshopper.
Um, dude. What?
Post a Comment