Created
May 18, 2016 16:41
-
-
Save s10018/4e2d467ada8298d27233cf4febf4dcc7 to your computer and use it in GitHub Desktop.
秒を与えて時間や分に
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/python | |
| # -*- coding: utf-8 -*- | |
| """ | |
| show what hours or minutes are XX seconds | |
| """ | |
| import argparse | |
| def main(args): | |
| funcs = { | |
| "h": lambda x: x / 60.0 / 60.0, | |
| "m": lambda x: x / 60.0, | |
| } | |
| label = {"h": "hour", "m": "minute"} | |
| for unit in args.unit: | |
| args.writer.write( | |
| "{}\t{:.3f}{}\n".format( | |
| label[unit].rjust(7, " "), | |
| funcs[unit](args.sec), unit | |
| ) | |
| ) | |
| def get_parser(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('sec', type=int) | |
| parser.add_argument( | |
| 'unit', nargs='+', choices=['h', 'm'] | |
| ) | |
| parser.add_argument( | |
| '-w', '--writer', type=argparse.FileType("w"), | |
| default='-' | |
| ) | |
| return parser | |
| if __name__ == '__main__': | |
| main(get_parser().parse_args()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment