首页 > 解决方案 > URL 未存储在文件中

问题描述

该 URL 未存储在文件“youtube_alarm_videos.txt”中。代码对我来说似乎很好,但它不起作用。有人可以帮我解决错误吗? 完整代码在这里

""" Alarm Clock
----------------------------------------

"""
import datetime
import os
import time
import random
import webbrowser
import winsound

# If video URL file does not exist, create one
url = print("Enter the link to the video below")
while True:
    url_input = input("Enter link:")
    break
else:
    print("Could not find the link entered. Please check and try again")
    
if not os.path.isfile("youtube_alarm_videos.txt"):
    with open("youtube_alarm_videos.txt", "w") as alarm_file:
        alarm_file.write(url_input)

标签: python

解决方案


我想你需要这样的东西

import datetime
import os
import time
import random
import webbrowser
import winsound

# If video URL file does not exist, create one

def create_file(filename="youtube_alarm_videos.txt"):
    # Create new file if doesn't exist
    with open(filename, 'w') as e:
        pass

url = print("Enter the link to the video below")
while True:
    url_input = input("Enter link:")
    break
else:
    print("Could not find the link entered. Please check and try again")
    
if os.path.isfile("youtube_alarm_videos.txt"):
    create_file()

with open("youtube_alarm_videos.txt", 'w') as e:
    e.write(url_input)

        

推荐阅读