If this method is wrong, then why does the interpreter output half of it?
I am a complete newbie to programming, I am doing zed shaw python. I played with the function than I am.
movies(mov1 = raw_input("first movie "), mov2 = raw_input("second movie "))
Now an interesting function is asking me for input, so it raw_input
works. But after that it shows
TypeError:movies() got an unexpected keyword argument 'mov1'
My question is, if this is syntactically incorrect, then why bother starting execution and why not a syntax error?
My function definition:
def movies(sci_fi, thriller):
print "So you like %r movie!!" %sci_fi
print "So you like %r movie!!" %thriller
print "Man those movies were awesome!!"
print "Now movie is finished..."
print "Get back to work. \n"
source to share
You have no syntax error. You have a runtime error.
Python is a very dynamic language. Since functions are objects, other code can replace your function at any time while your program is running, so Python won't know until you call that function that you are passing keyword arguments that the function does not support.
If you did this:
old_movies = movies
def movies(mov1, mov2):
return old_movies(mov1, mov2)
somewhere else in your program and then used
movies(mov1 = raw_input("first movie "), mov2 = raw_input("second movie "))
your program will be successful.
source to share