Python codecs do not work

I am experiencing a strange error (or is it an error?) With the python codec module . I am using Python 2.7.4.

Suppose I want to read the following file called foo :

 0 aaaa bbbb cddd dddddddd Long sentence here which is not even read completely The rest is ignored... 

I use the following code for this:

 import codecs log = codecs.open('foo', encoding='utf8') log.readline() lines = log.readlines() print ''.join(lines) 

The result is

 aaaa bbbb cddd dddddddd Long sentence here which is not even read com 

As you can see, the file is not fully readable!? !! Is there any explanation for this?

(The problem does not occur if I omit the readline call, or if I do not use any encoding ... This is all very mysterious to me.)

+2
source share

All Articles