puzzle about file Object.readlines()

MRAB python at mrabarnett.plus.com
Sat Mar 19 11:41:27 EDT 2011


On 19/03/2011 13:15, 林桦 wrote:
> i use python 2.5. os is window 7.
> the puzzle is :python don't read the leave text when meet character: 
> chr(26)
> the code is:
> /fileObject=open('d:\\temp\\1.txt','w')
> fileObject.write('22222222222222\r\n')
> fileObject.write(chr(26)+'\r\n')
> fileObject.write('33333333333333')
> fileObject.close()
> fileObject=open('d:\\temp\\1.txt','r')
> i=0
> for line in fileObject:
> i+=1
> print str(i)+'******'+line
> fileObject.close()/
> 
> the output only print:
> />>>
> 1******22222222222222/
> 
> but can't print next line text:/'33333333333333'' 。who tell me why?
> /
> 
chr(26) can sometimes be used in text files to indicate the end of the text.

In Microsoft Windows it dates from MS-DOS, which borrowed from CP/M, an
operating
system which stored the file size as the number of 128-byte records.
chr(26) was used to
indicate where the text ended in the last record.



More information about the Python-list mailing list