Storing lines from a text file

Kirk McDonald mooquack at suad.org
Sun Jan 29 19:21:35 EST 2006


bradfordh at gmail.com wrote:
> I keep getting an error when I try to use what you said Mr. McDonald. I
> think I've  got something wrong, but take a look if you can.
> 
> log = open('C:\log_0.txt')
> lines = log.getlines()
> for line in lines:
>      print line
> 
> When I debug it the error I get is the following:
>        AttributeError: 'file' object has no attribute 'getlines'
> 

D'oh! That's because the method is readlines(). Stupid brain:

log = open('C:\log_0.txt')
lines = log.readlines()
for line in lines:
     print line

-Kirk McDonald



More information about the Python-list mailing list