title: Python: TarFile.open No such file or directory
body: <p>So I'm fairly new to python and i'm writing a script that needs to untar a file. I use this simple function. </p>
  
  <pre><code>def untar(source_filename, dest_dir):
      for f in os.listdir():
          print(f)
  
      if(source_filename.endswith("tar.gz") or source_filename.endswith(".tar")):
          tar = tarfile.open(source_filename)
          tar.extractall(dest_dir)
          tar.close()
      else:
          raise Exception("Could not retrieve .depends for that file.")
  </code></pre>
  
  <p>I added the initial for loop for debugging purposes. When I invoke it, it prints out the name of the file i need in the current working directory meaning that it does exist. Here is the whole output.</p>
  
  <pre><code> dep.tar.gz
  Traceback (most recent call last):
    File "init.py", line 70, in &lt;module&gt;
      untar('dep.tar.gz', ".")
    File "init.py", line 17, in untar
      tar = tarfile.open(source_filename)
    File "/usr/lib/python3.4/tarfile.py", line 1548, in open
      return func(name, "r", fileobj, **kwargs)
    File "/usr/lib/python3.4/tarfile.py", line 1646, in bz2open
      compresslevel=compresslevel)
    File "/usr/lib/python3.4/bz2.py", line 102, in __init__
      self._fp = _builtin_open(filename, mode)
  FileNotFoundError: [Errno 2] No such file or directory: 'dep.tar.gz'
  </code></pre>
  
  <p>Can someone tell me how it can see the file in the working directory, and then suddenly not be able to see the file in the working directory?</p>