Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36959

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

From Peter Otten <__peter__@web.de>
Subject RE: iterating over the lines of a file - difference between Python 2.7 and 3?
Date 2013-01-17 18:59 +0100
Organization None
References <005f01cdf4d1$15836fd0$408a4f70$@biologie.uni-freiburg.de>
Newsgroups comp.lang.python
Message-ID <mailman.601.1358446382.2939.python-list@python.org> (permalink)

Show all headers | View raw


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: f.write("let's try\n")
... 
>>> import io
>>> with io.open("tmp.txt", "r") as f: print type(f.read())
... 
<type 'unicode'>
>>> with io.open("tmp.txt", "rb") as f: print type(f.read())
... 
<type 'str'>

So yes. Also:

>>> str is bytes
True

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

RE: iterating over the lines of a file - difference between Python 2.7 and 3? Peter Otten <__peter__@web.de> - 2013-01-17 18:59 +0100

csiph-web