Code block literals

Dave Benjamin ramen at
Thu Oct 9 19:09:00 CEST 2003

In article <840592e1.0310090454.4d95a170 at>, Hannu Kankaanp?? wrote:
> Dave Benjamin <dave at> wrote in message news:<u%0hb.113$_f.1 at>...
>> For instance, I always thought this was a cooler alternative to the 
>> try/finally block to ensure that a file gets closed (I'll try not to 
>> mess up this time... ;) :
>> open('input.txt', { |f|
>>      do_something_with(f)
>>      do_something_else_with(f)
>> })
> But being a function, it'd have the nasty property of a
> separate scope (yes, that can be nasty sometimes). I'd perhaps
> want to do
> open('input.txt', { |f| data = })
> But alas, 'data' would be local to the anonymous function and
> not usable outside.

Well, that's the same problem that lambda's got. I don't really have a
solution for that, other than the usual advice: "Use a namespace". =)


.:[ dave benjamin (ramenboy) -:- -:- ]:.
: d r i n k i n g   l i f e   o u t   o f   t h e   c o n t a i n e r :

More information about the Python-list mailing list