Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #24471 > unrolled thread
| Started by | Stefan Behnel <stefan_ml@behnel.de> |
|---|---|
| First post | 2012-06-26 19:22 +0200 |
| Last post | 2012-06-26 19:22 +0200 |
| 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.
Re: Frustrating circular bytes issue Stefan Behnel <stefan_ml@behnel.de> - 2012-06-26 19:22 +0200
| From | Stefan Behnel <stefan_ml@behnel.de> |
|---|---|
| Date | 2012-06-26 19:22 +0200 |
| Subject | Re: Frustrating circular bytes issue |
| Message-ID | <mailman.1521.1340731362.4697.python-list@python.org> |
J, 26.06.2012 18:30:
> def _reader(self, file, size=4096, delimiter=r"\n{2,}"):
> buffer_old = ""
> while True:
> buffer_new = file.read()
> print(type(buffer_new))
> if not buffer_new:
> break
> lines = re.split(delimiter, buffer_old + buffer_new)
"delimiter" is a Unicode string, which makes the regular expression a
Unicode regex that can't work on a byte string.
> buffer_old = lines.pop(-1)
>
> for line in lines:
> yield line
>
> yield buffer_old
>
>
> (the print statement is something I put in to verify the problem.
>
> So stepping through this, when _reader executes, it executes read() on
> the opened filehandle. Originally, it read in 4096 byte chunks, I
> removed that to test a theory. It creates buffer_new with the output
> of the read.
>
> Running type() on buffer_new tells me that it's a bytes object.
Stefan
Back to top | Article view | comp.lang.python
csiph-web