Search code examples
pythontarfile

Why does using tarfile.extract() result in error: no attribute 'extract'?


I'm using Python 3.4. Writing

csv_f = tarfile.open('C:\\Users\\somefile.gz')

works fine but this

csv_f = tarfile.extract('C:\\Users\\somefile.gz') 

causes the response

AttributeError: 'module' object has no attribute 'extract'

It seems the extract and extractall functions aren't being found in the library. How can that be?


Solution

  • Because they're methods of the object returned by tarfile.open(), not functions in the module itself.