Can Python respond to two lists 1:1?

Asked 2 years ago, Updated 2 years ago, 15 views

I'd like to rename the video file and caption file as a list on Python. What should I do at the end?

import os, glob

fpath = glob.glob('e:/utorrent/Neon Genesis Evangelion/*.smi')
movies = glob.glob('e:/utorrent/Neon Genesis Evangelion/*.mkv')
dirl = 'e:/utorrent/Neon Genesis Evangelion/'
nt = os.listdir('e:/utorrent/Neon Genesis Evangelion/')
data_list = []
r_name_list = []
for i in nt:
    if i.find('.smi') != -1:
        data_list.append(i)

for j in movies:
    if j.find('.mkv') != -1:
        tn = j.replace('mkv','smi')
        r_name_list.append(tn)

for k in data_list:
    pp = dirl + k
    os.rename(pp, r_name_list) <===== How can I print out the results here?

I'm still not good at repeating myself -ㅜ

python

2022-09-21 21:24

1 Answers

import os

dirl = 'e:/utorrent/Neon Genesis Evangelion/' nt = os.listdir(dirl) data_list = [] r_name_list = []

for i in nt: if i.find('.smi') != -1: pp = dirl + i data_list.append(pp) elif i.find('.mkv') != -1: tn = i.replace('mkv','smi') pp = dirl + tn r_name_list.append(pp) for j in data_list: os.rename(j, r_name_list.pop()) # Destination filename (refer to destination), name to replace

I solved it. I was able to complete it comfortably using pop using the target list.^

^


2022-09-21 21:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.