Mercurial > hg > config
comparison python/dictify.py @ 725:55a9ba575605
i need this actually for cdwin
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Wed, 05 Nov 2014 13:58:49 -0800 |
parents | python/example/dictify.py@6fc2a2001ac2 |
children | cd1ebc68739f |
comparison
equal
deleted
inserted
replaced
724:d547c071b847 | 725:55a9ba575605 |
---|---|
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 |