<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=iso-8859-1"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:70.85pt 70.85pt 56.7pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=DE link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span lang=EN-US>I just came across an unexpected behavior in Python 3.3, which has to do with file iterators and their interplay with other methods of file/IO class methods, like readline() and tell(): Basically, I got used to the fact that it is a bad idea to mix them because the iterator would use that hidden read-ahead buffer, so what you got with subsequent calls to readline() or tell() was what was beyond that buffer, but not the next thing after what the iterator just returned.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>Example:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>in_file_object=open(‘some_file’,’rb’)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>for line in in_file_object:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                print (line)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                if in_file_object.tell() > 300:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                               # assuming that individual lines are shorter<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                               break<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>This wouldnīt print anything in Python 2.7 since next(in_file_object) would read ahead beyond the 300 position immediately, as evidenced by a subsequent call to in_file_object.tell() (returning 8192 on my system).<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>However, I find that under Python 3.3 this same code works: it prints some lines from my file and after completing in_file_object.tell() returns a quite reasonable 314 as the current position in the file.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>I couldnīt find this difference anywhere in the documentation. Is the 3.3 behavior official, and if so, when was it introduced and how is it implemented? I assume the read-ahead buffer still exists?<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>By the way, the 3.3 behavior only works in binary mode. In text mode, the code will raise an OSError:  telling position disabled by next() call. In Python 2.7 there was no difference between the binary and text mode behavior. Could not find this documented either.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div></body></html>