Message52152
This is an implementation of __reversed__ for the TextIOWrapper type from the new IO interface (see http://docs.google.com/Doc?id=dfksfvqd_1cn5g5m). It is used as:
import io
for line in reversed(io.open(filename)):
...
It is efficient (only reads a block at a time) but can handle arbitrary length lines. It is useful for scanning backwards through big log files, but my main reason for submitting it is as a demonstration of the usefulness of the new IO layers - it works by putting a new buffering layer round the RawIOBase object from the open() call.
It's just a proof of concept, but if there's interest in this I'm happy to write unit tests and documentation.
The patch also makes io.BufferedReader support buffering, and adds a very minimal implementation of io.TextIOBase and io.TextIOWrapper (needed to make io.open() work).
|
|
Date |
User |
Action |
Args |
2007-08-23 15:57:26 | admin | link | issue1677872 messages |
2007-08-23 15:57:26 | admin | create | |
|