Beginner question : skips every second line in file when using readline()

peter leonard pfleonard at hotmail.com
Mon Oct 20 00:41:28 EDT 2003


Thanks Rob. This works fine.

Peter

>From: Rob Hunter <rob at cs.brown.edu>
>To: "peter leonard" <pfleonard at hotmail.com>
>Subject: Re: Beginner question : skips every second line in file when using 
>readline()
>Date: Sun, 19 Oct 2003 23:40:13 -0400
>
>Try this:
>
>handler = open('somefile.dat')
>for line in handler.readlines():
>	print line
>
>--Rob
>
>
>On Sunday, October 19, 2003, at 11:33 PM, peter leonard wrote:
>
>>Hi,
>>I having a problem with reading each line from a text file. For example, 
>>the file is a text file named 'test.txt' with the following content :
>>
>>line 1
>>line 2
>>line 3
>>line 4
>>line 5
>>
>>The following script attempts to print out each line :
>>
>>datafile ="C:\\Classifier\Data\\test.txt"
>>dataobject = open(datafile,"r")
>>
>>while dataobject.readline() !="":
>>
>>        line = dataobject.readline()
>>        print line
>>
>>However, the output from this script is :
>>
>>line 2
>>
>>line 4
>>
>>
>>I'm sure this is a simple problem but I can't figure it after loking up 
>>several reference books and web pages. Any help would be greatly 
>>appreciated.
>>
>>Regards
>>Peter
>>
>>_________________________________________________________________
>>Want to check if your PC is virus-infected?  Get a FREE computer virus 
>>scan online from McAfee.    
>>http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
>>
>>
>>--
>>http://mail.python.org/mailman/listinfo/python-list
>>
>

_________________________________________________________________
Add MSN 8 Internet Software to your current Internet access and enjoy 
patented spam control and more.  Get two months FREE!     
http://join.msn.com/?page=dept/byoa






More information about the Python-list mailing list