title: Global name 'key' is not defined
body: <p>I have a python program that run in loop to count the number of keys in bucket, it works fine when It has one or more keys. 
  It throws an error when it has 0 objects.</p>
  
  <pre><code>def CdmCount(Destbucket):
      global key
      totalcdms = 0
      for key in Destbucket.get_all_keys():
          totalcdms += 1
          print totalcdms
      assert isinstance (key,object )
      return (totalcdms, key)
  </code></pre>
  
  <p>I see following error:</p>
  
  <pre><code>  File "check_fun.py", line 24, in CdmCount
    return (totalcdms, key)
  NameError: global name 'key' is not defined
  </code></pre>
  
  <p>Complete code <a href="http://pastebin.com/QrAwL4Dq" rel="nofollow">http://pastebin.com/QrAwL4Dq</a></p>
  
  <p><strong>Update:</strong> </p>
  
  <p>After I add a upper level boto function to list the number of keys exist, if its zero exit.</p>
  
  <pre><code>    keys = list(Destbucket.list())
  if not keys:
      print "List is empty"
      sys.exit(2)
  </code></pre>
  
  <p>Is it a good approach? </p>