[Python-ideas] Automatic context managers

Bruce Leban bruce at leapyear.org
Fri Apr 26 21:46:57 CEST 2013


On Fri, Apr 26, 2013 at 12:37 PM, David Mertz <mertz at gnosis.cx> wrote:

> I'd note that there's no reason you couldn't use the so-called "automatic
> context manager" already, it's just a matter of writing your own function
> rather than the built-in 'open()'.  So, e.g. with a few lines of
> definition, you might use:
>
>   boolean = SafeOpen(resource).use()
>

I'd like to see those few lines if they are indeed possible. I don't see
how the function would know when to call __exit__. It has to be after use()
finishes.

--- Bruce
Latest blog post: Alice's Puzzle Page http://www.vroospeak.com
Learn how hackers think: http://j.mp/gruyere-security
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130426/a06bc39b/attachment.html>


More information about the Python-ideas mailing list