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

Jerry Hill malaclypse2 at
Tue Feb 1 14:38:37 EST 2011

On Tue, Feb 1, 2011 at 1:38 PM, Gerald Britton <gerald.britton at>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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list