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


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

Re: Error reading from 'urllib.request' and iterating over lines

Started byMRAB <python@mrabarnett.plus.com>
First post2014-08-30 22:39 +0100
Last post2014-08-30 22:39 +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: Error reading from 'urllib.request' and iterating over lines MRAB <python@mrabarnett.plus.com> - 2014-08-30 22:39 +0100

#77338 — Re: Error reading from 'urllib.request' and iterating over lines

FromMRAB <python@mrabarnett.plus.com>
Date2014-08-30 22:39 +0100
SubjectRe: Error reading from 'urllib.request' and iterating over lines
Message-ID<mailman.13656.1409434782.18130.python-list@python.org>
On 2014-08-30 21:16, Juan Christian wrote:
> My code: http://pastebin.com/CBgVvT4n
>
> Line 25 returns the text correctly [1], but it seems not being parsed
> to line 27-28 correctly. This is just a training program that I'm
> doing following some books/tutorials/docs, nothing special.
>
> [1] Output from line 25: http://pastebin.com/HSbAtDHQ
>
> Python 3.4.1
> PySide 1.2.2
>
You've called it 'fh', which suggests that it's a file. It isn't. It's
a bytestring (what the .read method return).

If you iterate over a file that's been opened as text, you'll get the
lines of the file, but you're iterating over a bytestring, which will
yield each byte (an int) in turn.

You should decoding the bytestring, split it into lines, and then
iterate over them.

[toc] | [standalone]


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


csiph-web