gpt4 book ai didi

python - 如何返回 endswith 函数中匹配的元组中的哪个元素

转载 作者:行者123 更新时间:2023-11-28 17:17:10 24 4
gpt4 key购买 nike

<分区>

我正在尝试使用 Python 进行文件重命名。我能够成功地从维基百科上抓取剧集列表,但在制作重命名文件时遇到了很多差异。我想要的是,我想完全使用与 if 条件匹配的扩展名,而不是最后的“.mkv”。有办法返回吗?

extensions = ('.webm','.mkv','.flv','.vob','.ogv', 
'.ogg','.drc','.gif','.gifv','.mng','.avi','.mov',
'.qt','.wmv','.yuv','.rm','.rmvb','.asf','.amv','.mp4',
'.m4p', '.m4v','.mpg', '.mp2', '.mpeg', '.mpe', '.mpv',
'.mpg', '.mpeg', '.m2v','.m4v','.svi','.3gp','.3g2','.mxf',
'.roq','.nsv','.f4v', '.f4p', '.f4a' ,'.f4b','.srt')
list = f.readlines()


y = 0
num = 1
for filename in os.listdir(path):
if filename.endswith(extensions):
os.rename(path+"\\"+filename,path+"\\"+str(num)+' - '+list[int(y)].strip('\n')+'.mkv') #instead of mkv, I want extension which was matched in the above if condition.
y += 1
num += 1

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com