[PyWart 1001] Inconsistencies between zipfile and tarfile APIs

Tim Chase python.list at tim.thechases.com
Fri Jul 22 07:25:36 EDT 2011

On 07/22/2011 03:26 AM, Lars Gustäbel wrote:
> On Thu, Jul 21, 2011 at 08:46:05PM -0700, rantingrick wrote:
>> Tarfile is missing the attribute "fp" and instead exposes a
>> boolean "closed". This mismatching API is asinine! Both
>> tarfile and zipfile should behave EXACTLY like file objects
> What do you prove when you say that tarfile has no "fp"
> attribute? You're not supposed to use the tarfile's internal
> file object, there is nothing productive you could do with
> it.

While I've needed access to such a fp object, it's been limited 
to cases where I passed a file-like object to the constructor 
instead of a path-name:

   tf = tarfile.open(fileobj=foo, ...)

so I had access to "foo" without reaching into the 
tarfile/zipfile object for the internal fp.  Usually this 
involves using a StringIO object or a temp-file that then gets 
cleaned up when complete.


More information about the Python-list mailing list