title: Python: using filter in tarfile
body: <p>I am writing a backup script which uses tarfile module. I am a beginner in python. Here is part of my script - 
  So I have a list of paths that need to be archived in tar.gz. seeing this <a href="https://stackoverflow.com/questions/16000794/python-tarfile-and-excludes">post</a>, I came up with following. Now archive gets created but the files with .tmp and .data extension aren't getting omitted. I am using python 3.5</p>
  
  <pre><code>L = [path1, path2, path3, path4, path5]
  exclude_files = [".tmp", ".data"]
  # print L
  
  def filter_function(tarinfo):
       if tarinfo.name in exclude_files:
            return None
       else:
            return tarinfo
  
  with tarfile.open("backup.tar.gz", "w:gz") as tar:
       for name in L:
          tar.add(name, filter=filter_function)
  </code></pre>