annotate python/dictify.py @ 913:107bf2430602

update with future work + links
author Jeff Hammel <k0scist@gmail.com>
date Mon, 27 May 2024 13:59:46 -0700
parents 4ebb6aff9d67
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
2
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
3 divider = ':'
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
4
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
5 def dictify(string):
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
6 lines = [ i.strip() for i in string.split('\n') if i.strip() ]
880
cd1ebc68739f -> python3
Jeff Hammel <k0scist@gmail.com>
parents: 725
diff changeset
7 return dict([i.split(divider,1) for i in lines
0
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
8 if len(i.split(divider,1)) == 2])
880
cd1ebc68739f -> python3
Jeff Hammel <k0scist@gmail.com>
parents: 725
diff changeset
9
0
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
10 if __name__ == '__main__':
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
11 import sys
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
12 feh = sys.stdin.read()
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
13 thedict = dictify(feh)
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
14 if sys.argv[1:]:
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
15 for i in sys.argv[1:]:
881
4ebb6aff9d67 no more has_key
Jeff Hammel <k0scist@gmail.com>
parents: 880
diff changeset
16 if i in thedict:
880
cd1ebc68739f -> python3
Jeff Hammel <k0scist@gmail.com>
parents: 725
diff changeset
17 print (thedict[i])
0
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
18 else:
880
cd1ebc68739f -> python3
Jeff Hammel <k0scist@gmail.com>
parents: 725
diff changeset
19 print (thedict)