Mercurial > hg > config
comparison python/example/dictify.py @ 723:6fc2a2001ac2
mv
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Tue, 04 Nov 2014 15:12:40 -0800 |
parents | python/dictify.py@f3ab51c79813 |
children |
comparison
equal
deleted
inserted
replaced
722:be9f792abaad | 723:6fc2a2001ac2 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 divider = ':' | |
4 | |
5 def dictify(string): | |
6 lines = [ i.strip() for i in string.split('\n') if i.strip() ] | |
7 return dict([i.split(divider,1) for i in lines | |
8 if len(i.split(divider,1)) == 2]) | |
9 | |
10 if __name__ == '__main__': | |
11 import sys | |
12 feh = sys.stdin.read() | |
13 thedict = dictify(feh) | |
14 if sys.argv[1:]: | |
15 for i in sys.argv[1:]: | |
16 if thedict.has_key(i): | |
17 print thedict[i] | |
18 else: | |
19 print thedict |