def prodInfo():
from collections import Counter
prodHolder = {}
tempdict = {}
try:
os.chdir(copyProd)
for root, dirs, files in os.walk('.'):
for data in files:
fullpath = os.path.join(root, data)
with open(fullpath, 'rt') as fp:
for info in fp:
info = info.strip()
if info.startswith('prodType'):
info0 = info.split('=')[1]
info0 = info0.replace(';','')
info0 = info0.replace('"','')
if info.startswith('acq'):
info1 = info.split('=')[1]
info1 = info1.replace(';','')
info1 = info1.replace('"','')
if info.startswith('ID_num'):
info2 = info.split('=')[1]
info2 = info2.replace(';','')
info2 = info2.replace('"','')
print info0 + info1 + info2
produces this result:
SD Acq645467 356788
SD Acq645467 356788
SD Acq645467 356788
SD Acq645467 356788
SD Acq645467 356788
SD Acq645467 356788
SD Acq645467 356788
SD Acq645467 356788
SD Acq645467 356788
Image Acq645467 356788
Image Acq645467 356788
Image Acq645467 356788
Image Acq645467 356788
SD Acq644869 356849
SD Acq644869 356849
Image Acq644869 356849
SD Acq644247 356851
SD Acq644247 356851
Image Acq644247 356851
I would like to store the results and have the ability to count the number of times 'SD' occurs for each specific Id number (356788/356849/356851) and how many 'images' for each Id number.
The results would be as follows:
9 - SD / 4 - Image for 356788
2 - SD / 1 - Image for 356849
2 - SD / 1 - Image for 356851
I though it would be best if I stored the items in a dictionary but have not been able to successfully count the values. This is the code I have used to store the info in a dictionary.
prodHolder[info2] = {'SD/Image': info0, 'Acq' : info1}
total_Acq = prodHolder
print prodHolder
Results are:
{'356788': {'SD/Image': 'SD', 'Acq': Acq645467'}} ...
Every time the function is run a different set of values will be entered thus producing a different result.