"I have a mind like a steel... uh... thingy." Patrick Logan's weblog.

Search This Blog

Monday, September 20, 2004

Python and Code Blocks

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
>>> fb2 = FooBar()
>>> fb2
__main__.FooBar instance at 24940415
>>> fb2.foo()
__main__.FooBar instance at 24940415
>> fb2.foo()
__main__.FooBar instance at 24940415
>>> fb.foo
method FooBar.foo of FooBar instance at 17493979
>>> fb2.foo
method FooBar.foo of FooBar instance at 24940415


Anonymous said...

i don't understand ... nothing ...

Anonymous said...

lost me too...

Anonymous said...

To catch the grasshopper you must first be the grasshopper.

Anonymous said...

Um, dude. What?

Blog Archive

About Me

Portland, Oregon, United States
I'm usually writing from my favorite location on the planet, the pacific northwest of the u.s. I write for myself only and unless otherwise specified my posts here should not be taken as representing an official position of my employer. Contact me at my gee mail account, username patrickdlogan.