[Tutor] readlines() ... problem [komodo weirdness / choose good variable names]

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Fri, 25 Jan 2002 18:27:41 -0800 (PST)


On Fri, 25 Jan 2002, James Roberts wrote:

> I have a file, a text file, that has 15 or so lines of text, each line
> ending in hard-return (Windows).  None of the lines are quoted, nor
> are they delimited by comma's, or anything else.
> 
> When I execute, in Komodo, a script that goes:
> 
> list = open("list")
> s = list.read()
> print s
> 
> ... I get the entire contents of the file printed out, just as it was
> in the source file.  This I expect.  But, if I do the following:
> 
> list = open("list")
> s = list.readlines()
> print list
        ^^^^


You probably mean:

###
print s
###

for the second example.  To avoid typos like that, you may want to change
the name of your variables to something like 'list_file' so that there's
less of a temptation to write "print list"... *grin*



> ... then, all I get is several of the lines from the source file.  
> The lines do output as a list, with the lines of the source presented
> as strings, with newlines at the end of each of the source lines, but
> the ouput is only a few of the lines from the source.


This is very odd!  You should be getting the whole file as a list of
lines, and not just a partial list.  Where does it cut off?  Perhaps
there's a strange character in there that Komodo is interpreting as a
wacky character.  I don't believe that Komodo should be doing that though.

If you can show us the text file that you're using, one of us at Tutor can
see if we can duplicate the error.


Good luck to you.