Python tarfile和排除

2024-05-01 21:28:24 发布

您现在位置:Python中文网/ 问答频道 /正文

这是Python文档的摘录:

If exclude is given it must be a function that takes one filename argument and returns a boolean value. Depending on this value the respective file is either excluded (True) or added (False).

我必须承认我不知道那是什么意思。

此外:

Deprecated since version 2.7: The exclude parameter is deprecated, please use the filter parameter instead. For maximum portability, filter should be used as a keyword argument rather than as a positional argument so that code won’t be affected when exclude is ultimately removed.

好的。。。以及“过滤器”的定义:

If filter is specified it must be a function that takes a TarInfo object argument and returns the changed TarInfo object. If it instead returns None the TarInfo object will be excluded from the archive.

。。。回到原点:)

我真正需要的是一种将排除的数组(或“:”分隔字符串)传递给tarfile.add的方法。

我不介意你试着解释一下那些来自PyDocs-ment的段落。

备注:

我突然想到:

  • 生成源目录内容列表的数组
  • 弹出排除
  • 对剩下的单个数组成员执行tar.add

但是,我想用一种更文明的方式来做


Tags: theifthatobjectisitfunction数组