{"id":5822,"date":"2014-04-07T09:30:05","date_gmt":"2014-04-07T09:30:05","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/07\/problem-about-contextmanager-collection-of-common-programming-errors\/"},"modified":"2014-04-07T09:30:05","modified_gmt":"2014-04-07T09:30:05","slug":"problem-about-contextmanager-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/07\/problem-about-contextmanager-collection-of-common-programming-errors\/","title":{"rendered":"problem about contextmanager-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/cb9730ee11d50fa2db955d687c653971?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nZearin<br \/>\npython with-statement contextmanager<br \/>\nI&#8217;m trying to use the with..as contruct in Python to make writing &#8220;reversible computing&#8221; 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 = L@contextlib.contextmanagerdef SymAdd(self, a):self.L.append(a)yieldself.L.append(a)SL = SymList() w<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/24780fb6df85a943c7aea0402c843737?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMartijn Pieters<br \/>\npython contextmanager<br \/>\nI&#8217;ve been playing around with making my own context managers in Python. I&#8217;m seeing some strange behavior most likely due to my implementation.I see the __exit__ code called before a statement in the &#8216;with&#8217; context. For example, here is the code snippet and it&#8217;s exception:with ProgressBar(10) as p:p.update(1)Traceback (most recent call last):File &#8220;&#8221;, line 3, in AttributeError: &#8216;NoneType&#8217; object has no attribute &#8216;update&#8217;I put debug in all the __enter__, __exit__, and update methods of my contex<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Zearin python with-statement contextmanager I&#8217;m trying to use the with..as contruct in Python to make writing &#8220;reversible computing&#8221; 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5822","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5822","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5822"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5822\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5822"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}