title: python and global variables
body: <p>How do I setup the global variable properly?</p>
  
  <pre><code># default objects is being set as None (null), after importing the piCamera library
  camera = None
  </code></pre>
  
  <p>after that I'm declaring the Webcam class with the <code>GET</code> definition:</p>
  
  <pre><code>class Webcam:
      def GET(self):
          web.header('Content-type','multipart/x-mixed-replace; boundary=--jpgboundary')
          stream=io.BytesIO()
          start=time.time()
  
          for foo in camera.capture_continuous(stream,'jpeg'):
              web.header('Content-type','--jpgboundary')
              web.header('Content-type','image/jpeg')
              web.header('Content-length',len(stream.getvalue()))
              yield (stream.getvalue())
              stream.seek(0)
              stream.truncate()
              time.sleep(.5)
  
  
  if __name__ == "__main__":
      camera = picamera.PiCamera()
      global camera
      camera.resolution = (640, 480)
      app = web.application(urls, globals())
      app.internalerror = web.debugerror
      app.run()
  </code></pre>
  
  <p>Should I put the <code>if __name__ == "__main__":</code> before I'm defining the Webcam class?</p>
  
  <p>Here's my traceback of the calls:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg/web/wsgiserver/__init__.py", line 1245, in communicate
      req.respond()
    File "/usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg/web/wsgiserver/__init__.py", line 775, in respond
      self.server.gateway(self).respond()
    File "/usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg/web/wsgiserver/__init__.py", line 2018, in respond
      response = self.req.server.wsgi_app(self.env, self.start_response)
    File "/usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg/web/httpserver.py", line 306, in __call__
      return self.app(environ, xstart_response)
    File "/usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg/web/httpserver.py", line 274, in __call__
      return self.app(environ, start_response)
    File "/usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg/web/application.py", line 281, in wsgi
      result = peep(result)
    File "/usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg/web/application.py", line 261, in peep
      firstchunk = iterator.next()
    File "/usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg/web/application.py", line 605, in wrap
      yield next()
    File "/usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg/web/application.py", line 597, in next
      return result.next()
    File "/home/pi/piApp/index.py", line 77, in GET
      for foo in camera.capture_continuous(stream,'jpeg'):
  AttributeError: 'NoneType' object has no attribute 'capture_continuous'
  </code></pre>