RIIA in Python 2.5 alpha: "with... as"

Alexander Myodov maa_subscriptions at sinn.ru
Tue Apr 11 08:56:41 EDT 2006


Hello Duncan,

You wrote:
> Alexander Myodov wrote:
>> So, with 2.5, I tried to utilize "with...as" construct for this, but
>> unsuccessfully:
>> ...
>> So, does this mean that we still don't have any kind of RIIA in
>> Python, any capability to localize the lifetime of variables on a
>> level less than a function, and this is indeed not gonna happen to
>> change yet?

> No, it means that Python 2.5 supports 'resource initialisation is
> acquisition', but that has nothing to do with the restricting the lifetime
> of a variable.
Sorry, I misworded the question - RIIA is indeed present at least by
the reason that the examples from PEP pass. Agree, my problem is a bit
different, and I a bit mixed up initialization/acquisition with
lifetime blocks. So, seems that we indeed have one and still don't
have another.
Or maybe you have an idea how this can be fixed? The
simplest way I see is putting all the "controlled" variables into a
dedicated class... and do that each time for each block of variables I
need control lifetime. Is there any simpler way?

-- 
With best regards,
 Alexander                          mailto:maa_subscriptions at sinn.ru





More information about the Python-list mailing list