[Tutor] Why does invalid syntax pop up?

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Jul 8 22:48:35 CEST 2005


>   Error Message:
>   Traceback (most recent call last):
>     File "D:\password.py", line 73, in ?
>       add_login_command()
>   TypeError: add_login_command() takes exactly 2 arguments (0 given)
>
>   How do I fix it so that it runs properly, and any other errors that have
>   to be fixed?


Hi Nathan,

Ok, so the error message is saying "I'm trying to call the
add_login_command, but as add_login_command is defined, it needs two
arguments.  Isn't this weird?"


Let's look at the definition of add_login_command():

######
def add_login_command(site,filename):
    print "Add a login info card"
    site = raw_input("Site: ")
    id = raw_input("User ID: ")
    passcard = raw_input("Password: ")
    sitelist[site] = [id,passcard]
######

It's not clear to me why 'site' and 'filename' are in the argument list,
as neither are being used as arguments, and no matter what we pass into
add_login_command, it looks like the function just ignores whatever it
sees.


There are two possible ways of fixing this:

    1.  When calling add_login_command(), just pass random garbage for
    those two parameters:

        add_login_command("foo", "bar")

    2.  Correct add_login_command() so that it doesn't take in two
    parameters.


I do not like option one.  *grin*  I strongly recommend fixing the
parameter list for add_login_command() so that it doesn't ask for
parameters that it never uses.


Best of wishes!



More information about the Tutor mailing list