[Python-ideas] Iterating non-newline-separated files should be easier

Paul Moore p.f.moore at gmail.com
Mon Jul 21 09:04:32 CEST 2014


On 21 July 2014 01:41, Andrew Barnert <abarnert at yahoo.com.dmarc.invalid> wrote:
> OK, I wrote up a draft PEP, and attached it to the bug (if that's not a good thing to do, apologies); you can find it at http://bugs.python.org/file36008/pep-newline.txt

As a suggestion, how about adding an example of a simple nul-separated
filename filter - the sort of thing that could go in a find -print0 |
xxx | xargs -0 pipeline? If I understand it, that's one of the key
motivating examples for this change, so seeing how it's done would be
a great help.

Here's the sort of thing I mean, written for newline-separated files:

import sys

def process(filename):
    """Trivial example"""
    return filename.lower()

if __name__ == '__main__':

    for filename in sys.stdin:
        filename = process(filename)
        print(filename)

This is also an example of why I'm struggling to understand how an
open() parameter "solves all the cases". There's no explicit open()
call here, so how do you specify the record separator? Seeing how you
propose this would work would be really helpful to me.

Paul


More information about the Python-ideas mailing list