Last active
October 25, 2018 04:08
-
-
Save newsch/9fdecc715a6f9d159fa89c9ac780cb1b to your computer and use it in GitHub Desktop.
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 | |
"""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