0

我编写了一个从服务器中提取各种构建的脚本。一旦我有了我需要的构建,我想将它发送到正确的提取函数,但首先我需要确定文件是什么endswith(7z、zip、bz2 等),但我的函数似乎没有返回任何结果。我将我的代码简化为基础,这就是我所拥有的。当我将 7z 文件传递​​给函数时,它什么也不返回。

target_build = 'C:\\my\\directory\\some_file.7z'

def decide_extract(target_build):
    if target_build.endswith('*.7z'):
        print(target_build)
    else:
        print('No build')

decide_extract(target_build)
4

1 回答 1

0

.endswith()已经在查看字符串的末尾,所以它实际上是在寻找字符串末尾的“*.7z”,在这种情况下,“*”不能用作通配符。

于 2018-08-20T17:03:44.960 回答