On Wednesday 04 November 2015 03:56, Tim Chase wrote:

> Or even more valuable to me:
> 
>   with open(..., newline="strip") as f:
>     assert all(not line.endswith(("\n", "\r")) for line in f)

# Works only on Windows text files.
def chomp(lines):
    for line in lines:
        yield line.rstrip('\r\n')


Better would be this:

def chomp(lines):
    for line in lines:
        yield line.rstrip()  # remove all trailing whitespace


with open(...) as f:
    for line in chomp(f): ...


-- 
Steve

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to