Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
show-newlines.py33 linesDownload Raw Back to text
1import autocommand2import inflect3from more_itertools import always_iterable4 5import jaraco.text6 7 8def report_newlines(filename):9    r"""10    Report the newlines in the indicated file.11 12    >>> tmp_path = getfixture('tmp_path')13    >>> filename = tmp_path / 'out.txt'14    >>> _ = filename.write_text('foo\nbar\n', newline='', encoding='utf-8')15    >>> report_newlines(filename)16    newline is '\n'17    >>> filename = tmp_path / 'out.txt'18    >>> _ = filename.write_text('foo\nbar\r\n', newline='', encoding='utf-8')19    >>> report_newlines(filename)20    newlines are ('\n', '\r\n')21    """22    newlines = jaraco.text.read_newlines(filename)23    count = len(tuple(always_iterable(newlines)))24    engine = inflect.engine()25    print(26        engine.plural_noun("newline", count),27        engine.plural_verb("is", count),28        repr(newlines),29    )30 31 32autocommand.autocommand(__name__)(report_newlines)33 
codekingpro/portable-devtools · Team Ai