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"
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.
This is not a syntax error. Its a "runtime" error. Your method movies
takes two parameters. It only detects that your parameters are wrong when the movie method is called and provides a parameter named mov1
(or mov2
)
raw_input fires before when the movie is called. Python is an interpreted language, so the video function signature is not checked against your call (which gives the wrong argument names).
Just one clarification. You don't store user input in variables mov1
and mov2
and pass them to functions. Instead, you are telling the function that its arguments mov1
and mov2
are user. Since the function has no arguments with these names, you get an error.