[Python-ideas] Add a .pop() method to ZipFile

Antoine Pitrou solipsis at pitrou.net
Fri May 10 15:44:04 CEST 2013


Le Fri, 10 May 2013 09:35:47 -0400,
Daniel Holth <dholth at gmail.com> a écrit :
> On Fri, May 10, 2013 at 9:22 AM, Masklinn
> <masklinn at masklinn.net> wrote:
> > On 2013-05-10, at 15:01 , Antoine Pitrou wrote:
> >
> >> Le Fri, 10 May 2013 08:32:17 -0400,
> >> Daniel Holth <dholth at gmail.com> a
> >> écrit :
> >>> Check out this efficient way to remove the last file from any
> >>> ordinary zip file.
> >>
> >> But why would you care such an operation? A generic remove()
> >> operation would sound more useful.
> >
> > Guessing it's because a generic `remove()` is less trivial to
> > implement, which would also be why the suggestion is for .pop() but
> > not .pop([index]): removing files at the end means you can just
> > truncate the archive and append the central directory[0], removing
> > files in the middle means either zeroing and leaving a hole or
> > moving all following files.
> 
> Yes, only the last file can be removed efficiently.

But what are the situations where you want to remove the last file with
certainty? It sounds like a rather specialized use-case.

If you make an analogy with sequences (list, bytearray), you can delete
any slice in a sequence, but it will be more efficient towards the end
(with a straightforward implementation, anyway :-)).

Regards

Antoine.





More information about the Python-ideas mailing list