From: Paul Prescod Date: 2003-03-21T07:17:35+09:00 Subject: Re: Strong advantages over Python Idan Sofer wrote: > Greg McIntyre wrote: > >> would be one focus of the lecture. But I'm interested in specific >> examples where the equivalent Python code is significantly more >> difficult. >> >> > Perhaps situation when you wish to do method run-time optimization. > >.... > data.txt is read only once per instance, but no run-time check(if @data) > is needed, Foo#parse just rewrites Foo#data at runtime as singleton method. > > There no such kind of technique in python AFAIK. I think that the more straightforward way of coding this is cleaner, but you can do it this way in Python too. (probably since Python 1.0, though you would use def instaead of lambda) class Foo: def parse(self, filehandle): # ... print "parsing" data = filehandle.read() Foo.data = lambda(self): data return data def data(self): filehandle = open("/tmp/test.txt") return self.parse(filehandle) a = Foo() print a.data() print a.data() print a.data() print a.data() print a.data() I'm not promoting Python but I'm going to correct inaccuracies I see! Paul Prescod