Mercurial > hg > config
comparison python/example/find_str_format.py @ 800:8275fa887f2b
cleanup + renaming
| author | Jeff Hammel <k0scist@gmail.com> |
|---|---|
| date | Fri, 28 Oct 2016 16:11:24 -0700 |
| parents | python/find_str_format.py@03b66f90916f |
| children |
comparison
equal
deleted
inserted
replaced
| 799:dbd2562cb03e | 800:8275fa887f2b |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 # -*- coding: utf-8 -*- | |
| 3 | |
| 4 """ | |
| 5 find str format options | |
| 6 """ | |
| 7 | |
| 8 import argparse | |
| 9 import os | |
| 10 import subprocess | |
| 11 import sys | |
| 12 | |
| 13 __all__ = ['main'] | |
| 14 | |
| 15 def find_keys(string): | |
| 16 retval = set() | |
| 17 while True: | |
| 18 try: | |
| 19 string.format(**{i:'' for i in retval}) | |
| 20 return retval | |
| 21 except KeyError as e: | |
| 22 retval.add(e.message) | |
| 23 | |
| 24 | |
| 25 def main(args=sys.argv[1:]): | |
| 26 | |
| 27 string = ' '.join(args) | |
| 28 keys = find_keys(string) | |
| 29 print ('\n'.join(sorted(keys))) | |
| 30 | |
| 31 if __name__ == '__main__': | |
| 32 main() |
