Last active
December 8, 2023 05:59
-
-
Save gh640/d2ae2363e9a062adb880d9fc6bfc4a1b to your computer and use it in GitHub Desktop.
Prefix lines with natural numbers.
This file contains 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 | |
"""Prefix lines with natural numbers.""" | |
import sys | |
from typing import Literal | |
NUMBER_SUFFIX = "." | |
def main() -> str | Literal[0]: | |
if sys.stdin.isatty(): | |
return "Stdin is a tty." | |
for i, line in enumerate(sys.stdin.readlines(), start=1): | |
print(f"{i}{NUMBER_SUFFIX} {line}", end="") | |
return 0 | |
if __name__ == "__main__": | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output: