[Tutor] How do I fix the following error? Code and error message supplied.

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Aug 4 04:45:41 CEST 2005

On Wed, 3 Aug 2005, Nathan Pinno wrote:

> Traceback (most recent call last):
>   File "D:\Python24\password.py", line 82, in -toplevel-
>     load_file(sitelist,filename)
>   File "D:\Python24\password.py", line 51, in load_file
>     [site,ID,passcard] = string.split(in_line,",")
>   File "D:\Python24\lib\string.py", line 292, in split
>     return s.split(sep, maxsplit)
> AttributeError: 'list' object has no attribute 'split'

Hi Nathan,

Let's pay attention to the line 51 in your file:

>     [site,ID,passcard] = string.split(in_line,",")

string.split() will fail if it is being given a set of arguments that it
doesn't understand.  string.split() works only if in_line is a string.

But in the function load_file(), in_line is a list of strings.  So there's
definitely a bug in load_file, in confusing the list of lines with a
particular single line.  Actuallly, a lot of load_file() needs some

We strongly recommend you go through:


because the code that you're writing to handle the reading of files is
using a very old style of Python that hasn't been seen since the Python
1.52 days; I suspect that you are learning from a very deprecated
tutorial! The approach that Alan takes in his "Learning How to Program"
tutorial uses a more modern, less bug-prone style of reading files.

More information about the Tutor mailing list