Message238699
| Author |
wolma |
| Recipients |
bkabrda, ethan.furman, georg.brandl, ncoghlan, paul.moore, python-dev, r.david.murray, sYnfo, serhiy.storchaka, vstinner, wolma |
| Date |
2015年03月20日.16:13:38 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1426868018.97.0.21995057526.issue23700@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
You are probably right that the io classes are broken.
From https://docs.python.org/3/library/stdtypes.html#iterator-types:
Once an iterator’s __next__() method raises StopIteration, it must continue to do so on subsequent calls. Implementations that do not obey this property are deemed broken.
One consequence of __iter__ returning self is that the above is not guaranteed:
>>> with open('somefile', 'w') as f:
f.write('some text')
9
>>> with open('somefile', 'r') as f:
i = iter(f)
assert f is i
for line in i:
print(line)
try:
next(i)
except StopIteration:
print('exhausted iterator')
f.seek(0)
print(next(i))
some text
exhausted iterator
0
some text
So the io classes are *officially* broken. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2015年03月20日 16:13:39 | wolma | set | recipients:
+ wolma, georg.brandl, paul.moore, ncoghlan, vstinner, r.david.murray, ethan.furman, python-dev, serhiy.storchaka, bkabrda, sYnfo |
| 2015年03月20日 16:13:38 | wolma | set | messageid: <1426868018.97.0.21995057526.issue23700@psf.upfronthosting.co.za> |
| 2015年03月20日 16:13:38 | wolma | link | issue23700 messages |
| 2015年03月20日 16:13:38 | wolma | create |
|