0

I'm completely new to Python and i'm trying to write a program that essentially works as an alarm clock. I prompt the user for a specific time to set the alarm to and then when that time occurs, a youtube video taken from a list of youtube videos in a txt file will play. However, I'm not quite sure why i'm getting this error, as i'm still largely unfamiliar with python syntax. Here's my code:

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

I'm getting this error:

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

If it helps this error occurs after the user enters y/n to whether not not they want to add a video to their list. Thanks for any help!

3
  • 1
    You have a name conflict. Use another name for the string object so addVideo only refers to the function Commented Dec 18, 2016 at 18:01
  • You can't use addVideo for both a function name and another variable. Function names are variables too. Rename one or the other. Commented Dec 18, 2016 at 18:01
  • You are confusing Python. You are using addVideo as the name for a string variable as well as for the name of a function. Just use a different name for one of these. Commented Dec 18, 2016 at 18:03

3 Answers 3

1

Problem is since you named both the function name and variable with the same name(addVideo),Python 'confuses' the function and variable.Rename any one of them:

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)

Output:

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: 
Sign up to request clarification or add additional context in comments.

1 Comment

ah thank you so much! I really only have experience with java and C so python's taking some getting used to!
0

You are overwriting the function addVideo() with a string: addVideo = raw_input("Would you like ...")

You need to rename the function or the varaible.

addVideoResult = raw_input("Would...")

if addVideoResult == 'y' or addVideoResult == 'n':
    addVideo()

Comments

0

You need a different name reference for raw_input("Would you like to add a video to your list? (y/n): \n") since you are overriding the function:

run = raw_input("Would you like to add a video to your list? (y/n): \n")
if run == 'y' or run == 'n':
    addVideo()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.