How can I tell if I am inside a context manager?

Jerry Hill malaclypse2 at gmail.com
Tue Feb 1 20:38:37 CET 2011


On Tue, Feb 1, 2011 at 1:38 PM, Gerald Britton <gerald.britton at gmail.com>wrote:

> As you can see, the object has a '__enter__' method regardless of how
> it was created.  Whatever the test, it needs to return False in the
> first case and True in the second case, without modifying the class
> definition.
>
>
I'm sorry, I completely misunderstood your question.  I thought you were
asking how you could tell if something provided a context manager.  Based on
the PEP[1], I don't see any generic way to tell if you are within a context
manager.

1: http://www.python.org/dev/peps/pep-0343/

-- 
Jerry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110201/a0441f68/attachment.html>


More information about the Python-list mailing list