Re: Closures / Blocks in Python

2007-07-25 Thread Gabriel Genellina
En Wed, 25 Jul 2007 11:45:00 -0300, Jeff <[EMAIL PROTECTED]> escribió: > You can create a lexical closure using a Python generator function, > which allows iteration using a block of code while maintaining > internal state. A generator is a regular function which uses yield > (like Ruby) to defin

Re: Closures / Blocks in Python

2007-07-25 Thread Jeff
True, and I should have known better than to not have thoroughly tested code I post to Usenet :). That being said, it was intended as a fast example of how a generator operates for someone coming from Ruby. -- http://mail.python.org/mailman/listinfo/python-list

Re: Closures / Blocks in Python

2007-07-25 Thread Klaas
On Jul 24, 7:58 am, treble54 <[EMAIL PROTECTED]> wrote: > Does anyone know a way to use closures or blocks in python like those > used in Ruby? Particularly those used in the { } braces. Inner functions allow you to define closures and (named) blocks anywhere). Anonymous blocks must consist of a

Re: Closures / Blocks in Python

2007-07-25 Thread Wildemar Wildenburger
Jeff wrote: > # Generic counter > def counter(min=None, max): > if not min: > min = 0 > for i in xrange(min, max): > yield i > i = i + 1 > Just for the record: >>> # Generic counter ... def counter(min=None, max): ... if not min: ... min = 0 ... for i in xrange(min, max)

Re: Closures / Blocks in Python

2007-07-25 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Jason <[EMAIL PROTECTED]> wrote: . [good detail] . . >If you can't find a way of doing what you want with iterators, >comprehensions, or lambda, consider writing a little functio

Re: Closures / Blocks in Python

2007-07-25 Thread Jeff
You can create a lexical closure using a Python generator function, which allows iteration using a block of code while maintaining internal state. A generator is a regular function which uses yield (like Ruby) to define the point at which the function should return an expression to the calling cod

Re: Closures / Blocks in Python

2007-07-24 Thread Bruno Desthuilliers
treble54 a écrit : > Does anyone know a way to use closures or blocks in python like those > used in Ruby? Particularly those used in the { } braces. > Instead of looking for what you think is the solution, you'd be better explaining your concrete problem. -- http://mail.python.org/mailman/listi

Re: Closures / Blocks in Python

2007-07-24 Thread Jason
On Jul 24, 8:58 am, treble54 <[EMAIL PROTECTED]> wrote: > Does anyone know a way to use closures or blocks in python like those > used in Ruby? Particularly those used in the { } braces. Python isn't Ruby. Python has a lambda function for creating anonymous functions, but many of the common use c

Re: Closures / Blocks in Python

2007-07-24 Thread Neil Cerutti
On 2007-07-24, treble54 <[EMAIL PROTECTED]> wrote: > Does anyone know a way to use closures or blocks in python like > those used in Ruby? Particularly those used in the { } braces. Python's nameless functions are week. So it supports iterators and generators using protocols, comprehensions and a

Re: Closures / Blocks in Python

2007-07-24 Thread Carsten Haese
On Tue, 2007-07-24 at 14:58 +, treble54 wrote: > Does anyone know a way to use closures or blocks in python like those > used in Ruby? Particularly those used in the { } braces. Please describe the problem you're trying to solve. Even if Python had a direct equivalent of "Ruby closures or bloc

Closures / Blocks in Python

2007-07-24 Thread treble54
Does anyone know a way to use closures or blocks in python like those used in Ruby? Particularly those used in the { } braces. -- http://mail.python.org/mailman/listinfo/python-list