私は何かを理解していないようです---pythonwith
ステートメント。
このクラスを考えてみましょう:
class test(object):
def __enter__(self): pass
def __exit__(self, *ignored): pass
今、with
のようにそれを使用する場合
with test() as michael:
print repr(michael)
<test instance at memore blah> のような出力が期待できます。しかし、私はNoneを取得します。
ここで何か問題がありますか?どんな提案も役に立ちます。
(私は Python 2.6.6 を使用しています。)
編集:
ドキュメントを教えてくれたephementに感謝し
ます。__enter__
メソッドは次のように読む必要があります
def __enter__(self): return self