Christian Heimes <[EMAIL PROTECTED]> wrote:

>> res = create_resource()
>> try:
>>    use_resource()
>> finally:
>>    res.close() # Must free resource, but the object can still be
>>    alive... 
> 
> You can replace the try/finally code with a "with resource:
> do_something()" block if the object supporst the context manager
> protocol. 
> 

or replace it with:

 with contextlib.closing(create_resource()) as res:
     do_something()

if the object does not support the context manager protocol.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to