On Feb 6, 2013, at 11:54 , Duncan Booth <duncan.booth@suttoncourtenay.org.uk> wrote:
Chris Withers <chris@simplistix.co.uk> wrote:
Hi All,
I used to do this:
import transaction with transaction: ... print 'hello' ... Traceback (most recent call last): File "<console>", line 1, in <module> AttributeError: __exit__
When did that stop working and what should I now do instead?
cheers,
Chris
You can use pure hackery to work around this: ----- t.py ----- def __enter__(*args): print 'enter', args
def __exit__(*args): print 'exit', args
def fixup(): import sys, types self = sys.modules[__name__] mymod = type(__name__, (types.ModuleType,), globals()) sys.modules[__name__] = mymod(__name__) fixup()
You can also use the transaction manager directly instead of the bound methods transaction lifts out of it: import transaction with transaction.manager: pass Wichert.