-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
John Pfuntner
committed
Dec 9, 2024
1 parent
a76409d
commit 236cf11
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import re | ||
import sys | ||
import signal | ||
import logging | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser(description='Display number of tokens from stdin') | ||
parser.add_argument('-v', '--verbose', action='count', help='Enable debugging') | ||
args = parser.parse_args() | ||
|
||
logging.basicConfig(format='%(asctime)s %(levelname)s %(pathname)s:%(lineno)d %(msg)s') | ||
log = logging.getLogger(sys.argv[0]) | ||
log.setLevel(logging.WARNING - (args.verbose or 0)*10) | ||
|
||
signal.signal(signal.SIGPIPE, lambda signum, stack_frame: exit(0)) | ||
|
||
if sys.stdin.isatty(): | ||
parser.error('stdin must be redirected') | ||
|
||
for line in sys.stdin.read().splitlines(): | ||
print(len(re.split(r'\s+', line.strip()))) |