title: Creating a zip file with compression in python using the zipfile module
body: <p>I am new to python. My requirement is to zip (with compression) all files from a source directory to a target directory. I have used following code from stackOverFlow.</p>
  <pre><code>import zipfile, os
  locfile = &quot;D:\Python\Dir_dir\Dir_dir\ABC.txt&quot;
  loczip = &quot;D:\Python\Dir_dir\Dir_dir2\ABC_TEST.zip&quot;
  zip = zipfile.ZipFile (loczip, &quot;w&quot;)
  zip.write (locfile)
  zip.close()
  </code></pre>
  <p>It is creating a zip file but it contains the entire inherited directory structure. Except the drive(D:/) the rest of the structure is added to zip. It looks like the following:
  &quot;D:\Python\Dir_dir\Dir_dir2\ABC_TEST.zip\Python\Dir_dir\Dir_dir\ABC.txt&quot;</p>
  <p>whereas i wanted:
  &quot;D:\Python\Dir_dir\Dir_dir2\ABC_TEST.zip\ABC.txt&quot;</p>
  <p>Also it is not compressed.</p>