title: How do I specify the compression level of a zip file in python?
body: <p>How do I zip a file in python and how do specify the compression level ? </p>
  
  <p>I have the below code so far and the error I get is: </p>
  
  <pre><code>Zip("log4j.dl-service.log.2013-05-03-22",9)
  AttributeError: 'str' object has no attribute 'ZipFile'
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>import zipfile
  import fileinput
  
  def Zip(file,level):
      """
      This function uses the zip library native to python to compress files with
      Usage: Zip(file,level)
      """
  
      if file and level:
          try:
              zipfile = file+'.zip'
              output = zipfile.ZipFile(zipfile, 'wb')
              for line in fileinput.input(file):
                  output.write(line)
              output.close()
              if os.path.exists(zipfile):
                  return zipfile
              else:
                  logMe('critical',"zip failed in Zip()")
                  return False
  
          except Exception,e:
              logMe('critical',e)
  </code></pre>