title: Using Python to add a list of files into a zip file
body: <p>I want to write a script to add all the ‘.py’ files into a zip file.</p>
  
  <p>Here is what I have:</p>
  
  <pre><code>import zipfile
  import os
  
  working_folder = 'C:\\Python27\\'
  
  files = os.listdir(working_folder)
  
  files_py = []
  
  for f in files:
      if f[-2:] == 'py':
          fff = working_folder + f
          files_py.append(fff)
  
  ZipFile = zipfile.ZipFile("zip testing.zip", "w" )
  
  for a in files_py:
      ZipFile.write(a, zipfile.ZIP_DEFLATED)
  </code></pre>
  
  <p>However it gives an error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Python27\working.py", line 19, in &lt;module&gt;
      ZipFile.write(str(a), zipfile.ZIP_DEFLATED)
    File "C:\Python27\lib\zipfile.py", line 1121, in write
      arcname = os.path.normpath(os.path.splitdrive(arcname)[1])
    File "C:\Python27\lib\ntpath.py", line 125, in splitdrive
      if p[1:2] == ':':
  TypeError: 'int' object has no attribute '__getitem__'
  </code></pre>
  
  <p>so seems the file names given is not correct.</p>