如何删除在python脚本中使用的文件?

import os
import shutil
from pytube import YouTube
import random
import string
import uuid
import time
from datetime import date
from datetime import datetime
from time import gmtime,strftime
from moviepy.editor import VideoFileclip,VideoClip,AudioFileclip,AudioClip
import tkinter as tk
from tkinter import filedialog
import random

yt = YouTube
print ('What youtube video would you like too download and convert to .mp3?(Insert Link)')
ytv = input()

try:
    lol = yt(ytv).streams.first().download()
except:
    print ('That is not a YouTube link')
    exit()

today = strftime('%Y-%m-%d',gmtime())

video1 = os.path.join(os.path.join(os.environ['USERPROFILE']),'Videos')

title = yt(ytv).streams[0].default_filename

title1 = '\\' + yt(ytv).streams[0].default_filename

random = uuid.uuid4().hex.upper()[0:6]

name = random + '-' + today + '.mp4'

current = os.getcwd()

os.rename(current + title1,name)
shutil.move(current + '\\' + name,video1)

random = random = uuid.uuid4().hex.upper()[0:6]

video = VideoFileclip(video1 + '\\' + name)

print ('The audio file will be in your downloads folder')
save = os.path.join(os.path.join(os.environ['USERPROFILE']),'Downloads')

video.audio.write_audiofile(save + '\\' + random + '.mp3')

整个脚本只是下载一个 youtube 视频,将其发送到一个文件夹,该文件夹运行一个 api,将下载的视频转换为 mp3 文件。在这里,我想删除该文件,以便用户只有一个 .mp3,但它有某种锁定,我无法解锁/弄清楚。

os.remove(video1 + '\\' + name)
SHEN453927422 回答:如何删除在python脚本中使用的文件?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1137536.html

大家都在问