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

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

我正在使用 Python 3.4。 写作

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

工作正常但是这个

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

引起反应

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

似乎在库中找不到 extract 和 extractall 函数。怎么可能?

因为它们是 tarfile.open() 返回的对象的方法,而不是模块本身的函数。