为什么在使用 endswith() 时无法识别我的文件

Why isnt my file recognised when using endswith()

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

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)

.endswith() 已经在寻找字符串的末尾,所以它实际上是在寻找字符串末尾的“*.7z”,“*”在这种情况。