title: Skipping execution of -with- block
body: <p>I am defining a context manager class and I would like to be able to skip the block of code without raising an exception if certain conditions are met during instantiation. For example,</p>
  
  <pre><code>class My_Context(object):
      def __init__(self,mode=0):
          """
          if mode = 0, proceed as normal
          if mode = 1, do not execute block
          """
          self.mode=mode
      def __enter__(self):
          if self.mode==1:
              print 'Exiting...'
              CODE TO EXIT PREMATURELY
      def __exit__(self, type, value, traceback):
          print 'Exiting...'
  
  with My_Context(mode=1):
      print 'Executing block of codes...'
  </code></pre>