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


Groups > comp.lang.python > #36959 > unrolled thread

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

Started byPeter Otten <__peter__@web.de>
First post2013-01-17 18:59 +0100
Last post2013-01-17 18:59 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

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

FromPeter Otten <__peter__@web.de>
Date2013-01-17 18:59 +0100
SubjectRE: iterating over the lines of a file - difference between Python 2.7 and 3?
Message-ID<mailman.601.1358446382.2939.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web