problem about contextmanager-Collection of common programming errors


  • Zearin
    python with-statement contextmanager
    I’m trying to use the with..as contruct in Python to make writing “reversible computing” code easier. However, using @contextmanager on a class method seems to change the default initialization of future class instances. Python 2.6 and 3.1 have the same behavior. Here is a simple example exhibiting this behavior:#!/usr/bin/env pythonimport contextlibclass SymList:def __init__(self, L=[]):self.L = [email protected] SymAdd(self, a):self.L.append(a)yieldself.L.append(a)SL = SymList() w

  • Martijn Pieters
    python contextmanager
    I’ve been playing around with making my own context managers in Python. I’m seeing some strange behavior most likely due to my implementation.I see the __exit__ code called before a statement in the ‘with’ context. For example, here is the code snippet and it’s exception:with ProgressBar(10) as p:p.update(1)Traceback (most recent call last):File “”, line 3, in AttributeError: ‘NoneType’ object has no attribute ‘update’I put debug in all the __enter__, __exit__, and update methods of my contex

Web site is in building