who can give me a code example on '__enter__' and '__exit__',i can't understand Completely only use api
<p>this is i saw in someone's code: </p>

<pre><code>    def __enter__(self):
        return self

    def __exit__(self, type, value, tb):
        self.stream.close()
</code></pre>

<p>thanks</p>

<hr>

<pre><code>from __future__ import with_statement#for python2.5 

class a(object):
    def __enter__(self):
        print 'sss'
        return 'sss111'
    def __exit__(self ,type, value, traceback):
        print 'ok'
        return False

with a() as s:
    print s


print s
</code></pre>
