Skip to content

Instantly share code, notes, and snippets.


sakp/ Secret

Created Sep 10, 2014
What would you like to do?
import sys
import glob
import re
def format_it(inp):
outp = {}
for i,k in zip(inp[0::2], inp[1::2]):
outp[i] = k;
return outp
def merge_it(inp):
out = []
for rec_key, rec_value in inp.items():
return "\t".join(out)
for datarec_file in glob.glob("./invt/*/data.rec"):
read_data = ""
f = open(datarec_file, 'r')
read_data =
formatted_splited = format_it(read_data.strip().split("\t"));
maxkey = 0;
for rec_key, rec_value in formatted_splited.items():
result = re.match( r'^medname([0-9]+)', rec_key, re.M|re.I)
if result:
keynum = int(;
medname = 'medname'+str(keynum)
medk = 'medk'+str(keynum)
if re.match( r'^attr', formatted_splited[medname], re.M|re.I):
if maxkey < keynum:
maxkey = keynum
formatted_splited[medk] = "swatch"
if maxkey > 0:
print("processing .. ("+str(maxkey)+")", formatted_splited['ref'])
formatted_splited['medtot'] = str(maxkey)
f = open (datarec_file, 'w')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment