Re: iterating over the lines of a file - difference between Python 2.7 and 3?

2013-01-17 Thread Peter Otten
Wolfgang Maier wrote: 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

Re: iterating over the lines of a file - difference between Python 2.7 and 3?

2013-01-17 Thread Terry Reedy
On 1/17/2013 7:04 AM, Peter Otten wrote: Wolfgang Maier wrote: 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

RE: iterating over the lines of a file - difference between Python 2.7 and 3?

2013-01-17 Thread Wolfgang Maier
Thanks Peter, for this very helpful reply and for pointing out _pyio.py to me! It's great to be able to check implementation details sometimes. So, if I understand you correctly, I can simply import io and open files with io.open() - instead of open and although this is a bit a detour in Python3

RE: iterating over the lines of a file - difference between Python 2.7 and 3?

2013-01-17 Thread Peter Otten
Wolfgang Maier wrote: What will my IO object return then when I read from it in Python 2.7? str where Python3 gives bytes, and unicode instead of str ? This is what I understood from the Python 2.7 io module doc. You can always double-check in the interpreter: with open(tmp.txt, w) as f: