Skip to content
Snippets Groups Projects
Commit c766b066 authored by dimitri.lizzi's avatar dimitri.lizzi
Browse files

rapport: fix bug in trimming script

parent 272917a5
Branches
No related tags found
No related merge requests found
#!/usr/bin/env python3 #!/usr/bin/env python3
from argparse import ArgumentParser
from fileinput import input
from sys import stdout
import sys from typing import Iterable, Iterator
nonempty_line_reached = False
for i, line in enumerate(sys.stdin): def lstrip_stream(stream: Iterable[str]) -> Iterator[str]:
if not nonempty_line_reached: """
if line.rstrip() == "": Skips the leading whitespace at the beginning of a stream of strings.
continue :param stream: Iterable[str] A buffered stream of string.
nonempty_line_reached = True :return: Generator[str] An iterator that yields the data from the input stream once the first non-whitespace
print(line, end='') character is reached.
"""
for first_nonempty_buffer in filter(bool, map(str.lstrip, stream)):
yield first_nonempty_buffer
break
else:
return
yield from stream
def handle_args():
parser = ArgumentParser()
parser.add_argument(
'files',
metavar='FILE',
nargs='*',
help='Files to read sequentially as one stream. If no file is given, stdin is read instead.'
)
parser.parse_args()
if __name__ == '__main__':
handle_args()
with input() as input_stream:
for line in lstrip_stream(input()):
stdout.write(line)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment