Canonical way of dealing with null-separated lines?

Christopher De Vries devries at idolstarastronomer.com
Thu Feb 24 14:51:07 EST 2005


On Thu, Feb 24, 2005 at 02:03:52PM -0500, Douglas Alan wrote:
> Thanks for the generator.  It returns an extra blank line at the end
> when used with "find -print0", which is probably not ideal, and is
> also not how the normal file line iterator behaves.  But don't worry
> -- I can fix it.

Sorry... I forgot to try it with a null terminated string. I guess it further
illustrates the power of writing good test cases. Something like this would
help: 

    # yield anything left over
    if retain[0]:
        yield retain[0]

The other modification would be an option to ignore multiple nulls in a row,
rather than returning empty strings, which could be done in a similar way.

Chris



More information about the Python-list mailing list