[Tutor] What's wrong with this code?

Andre Engels andreengels at gmail.com
Thu Jul 7 12:57:43 CEST 2005

On 7/7/05, Nathan Pinno <falcon3166 at hotmail.com> wrote:
>   Hi all,
>   I meant to ask why the main part after the password is not working right.
> No one has answered that yet. When I run the code and try to load a file
> that has been saved, a TypeError appears. How do I fix the code so no more
> errors will show up. Here is the newest code so far:

I don't get a TypeError, but a NameError. Reason is the line:
    filename == raw_input("Filename to load: ")
which should be:
    filename = raw_input("Filename to load: ")

After correcting this, I get the TypeError. And the error clearly says
what is wrong: in_file is a file object, and those do not have the
value "len". I think what you mean is done by replacing:
    if len(in_file) == 0:
    if len(in_line) == 0:

In general, in such cases, check the error message. In this case it
said "len() of an unsized object". There is only one len() in the line
given, so that must be it, and thus in_file must be that 'unsized

Andre Engels

More information about the Tutor mailing list