저는 Python을 처음 접했고 기본적으로 알람 시계로 작동하는 프로그램을 작성하려고합니다. 사용자에게 알람을 설정할 특정 시간을 묻는 메시지를 표시 한 다음 해당 시간이 발생하면 txt 파일의 YouTube 동영상 목록에서 가져온 YouTube 동영상이 재생됩니다. 그러나 여전히 파이썬 구문에 익숙하지 않기 때문에 왜이 오류가 발생하는지 잘 모르겠습니다. 내 코드는 다음과 같습니다.
import time
def addVideo():
videoToAdd = raw_input("Enter the url of the video to add: ")
with open('alarmVideos.txt', 'w') as f:
f.write(videoToAdd + '\n')
alarmTime = raw_input("When would you like to set your alarm to?: \nPlease use this format: 01:00\n")
localTime = time.strftime("%H:%M")
addVideo = raw_input("Would you like to add a video to your list? (y/n): \n")
if addVideo == 'y' or addVideo == 'n':
addVideo()
print "Your alarm is set to:", alarmTime
이 오류가 발생합니다.
Traceback (most recent call last):
File "C:\Users\bkrause080\Desktop\Free Time Projects\LearningPythonProjects\alarmClock.py", line 15, in <module>
addVideo()
TypeError: 'str' object is not callable
도움이된다면 사용자가 비디오를 목록에 추가 할 것인지 여부에 대해 y / n을 입력 한 후이 오류가 발생합니다. 도움을 주셔서 감사합니다!
문제는 함수 이름과 변수를 같은 이름 (addVideo)으로 명명했기 때문에 Python이 함수와 변수를 '혼동'합니다.
import time
def addVideo():
videoToAdd = raw_input("Enter the url of the video to add: ")
with open('alarmVideos.txt', 'w') as f:
f.write(videoToAdd + '\n')
alarmTime =raw_input("When would you like to set your alarm to?: \nPlease use this format: 01:00\n")
localTime = time.strftime("%H:%M")
add_Video = raw_input("Would you like to add a video to your list? (y/n): \n")
if add_Video == 'y' or add_Video == 'n':
addVideo()
print( "Your alarm is set to:", alarmTime)
산출:
When would you like to set your alarm to?:
Please use this format: 01:00
Would you like to add a video to your list? (y/n):
n
Enter the url of the video to add: grg
Your alarm is set to:
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다