Skip to content

Instantly share code, notes, and snippets.

@newsch
Last active October 25, 2018 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save newsch/9fdecc715a6f9d159fa89c9ac780cb1b to your computer and use it in GitHub Desktop.
Save newsch/9fdecc715a6f9d159fa89c9ac780cb1b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""Print a horizontal or vertical enumeration.
Need to figure out how many characters tall or wide something is in a pinch?
This is the commandline utility for you!
"""
import argparse
parser = argparse.ArgumentParser(
description='Print a horizontal or vertical enumeration.')
parser.add_argument('-l', '--length', type=int, default=99,
help='Number of characters to print. Default: 99')
direction = parser.add_mutually_exclusive_group(required=True)
direction.add_argument('-H', '--horizontal', action='store_true',
help='Print numbers horizontally')
direction.add_argument('-V', '--vertical', action='store_true',
help='Print numbers vertically')
args = parser.parse_args()
FORMAT_STR = '{{:0={}}}'.format(len(str(args.length))) # zero-pad numbers
if args.horizontal:
# horizontal test
nums = [FORMAT_STR.format(num) for num in range(1, args.length+1)]
digits = map(list, nums)
lines = [''.join(row) for row in zip(*digits)]
[print(line) for line in lines]
if args.vertical:
# vertical test
nums = [FORMAT_STR.format(num) for num in range(1, args.length+1)]
[print(line) for line in nums]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment