Am 22.09.2011 12:21 schrieb Gavin Panella:
Hi,

On Python 2.6 and 3.1 the following code works fine:

     class Foo(object):

         @classmethod
         def __enter__(cls):
             print("__enter__")

         @classmethod
         def __exit__(cls, exc_type, exc_value, traceback):
             print("__exit__")

     with Foo: pass

However, in 2.7 and 3.2 I get:

     Traceback (most recent call last):
       File "<stdin>", line 1, in<module>
     AttributeError: __exit__

Same here.

But

    with Foo(): pass

works, and that is more important and more logical.


Thomas
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to