Generate the lines of file in reverse order.
(fin)
| 242 | |
| 243 | |
| 244 | def reversed_lines(fin): |
| 245 | """Generate the lines of file in reverse order.""" |
| 246 | part = '' |
| 247 | for block in reversed_blocks(fin): |
| 248 | if PY3PLUS: |
| 249 | block = block.decode("utf-8") |
| 250 | for c in reversed(block): |
| 251 | if c == '\n' and part: |
| 252 | yield part[::-1] |
| 253 | part = '' |
| 254 | part += c |
| 255 | if part: |
| 256 | yield part[::-1] |
| 257 | |
| 258 | |
| 259 | def reversed_blocks(fin, block_size=4096): |
no test coverage detected