Created
May 26, 2025 03:18
-
-
Save Techcable/e294d1ce5900b1e31a9a62e7dd0c6096 to your computer and use it in GitHub Desktop.
Slowly print lines, for testing command line interfaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Print lines slowly | |
Intended for testing command line interfaces | |
""" | |
import argparse | |
import itertools | |
import time | |
from collections.abc import Iterable | |
def print_slowly(amount: int | None, /, *, delay: float) -> None: | |
source: Iterable[int] | |
if amount is None: | |
source = itertools.count(1) | |
else: | |
source = range(1, amount + 1) | |
for index in source: | |
time.sleep(delay) | |
print("Line", index) | |
def main() -> None: | |
parser = argparse.ArgumentParser( | |
prog="slowprint", description="Prints lines slowly" | |
) | |
parser.add_argument( | |
"amount", | |
help="The number of lines to print, infinite if unspecified", | |
nargs="?", | |
type=int, | |
) | |
parser.add_argument( | |
"-d", | |
"--delay", | |
help="The seconds to wait between printing each line", | |
type=float, | |
default=1, | |
) | |
args = parser.parse_args() | |
print_slowly(args.amount, delay=args.delay) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment