annotate python/example/find_str_format.py @ 868:0c505e8fdad7

py3
author Jeff Hammel <k0scist@gmail.com>
date Fri, 17 Aug 2018 16:19:42 -0700
parents 8275fa887f2b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
726
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 """
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 find str format options
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6 """
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 import argparse
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 import os
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 import subprocess
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 import sys
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 __all__ = ['main']
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 def find_keys(string):
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 retval = set()
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 while True:
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 try:
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 string.format(**{i:'' for i in retval})
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 return retval
727
Jeff Hammel <k0scist@gmail.com>
parents: 726
diff changeset
21 except KeyError as e:
Jeff Hammel <k0scist@gmail.com>
parents: 726
diff changeset
22 retval.add(e.message)
Jeff Hammel <k0scist@gmail.com>
parents: 726
diff changeset
23
726
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 def main(args=sys.argv[1:]):
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27 string = ' '.join(args)
727
Jeff Hammel <k0scist@gmail.com>
parents: 726
diff changeset
28 keys = find_keys(string)
Jeff Hammel <k0scist@gmail.com>
parents: 726
diff changeset
29 print ('\n'.join(sorted(keys)))
726
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
30
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31 if __name__ == '__main__':
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
32 main()