My target is to count offers to specified companies in Excel.
I used plenty of if statements to do counting work before. codes like below
ipl=gs=gt=0
for file in glob.glob('*.xlsm'):
wb=load_workbook(file,data_only=True)
ws=wb["Tim"]
client=ws['B2'].value
if client=='Injection Parts Ltd.':
ipl+=1
if client=='Gulf Sample Ltd':
gs+=1
if client=='Great test Ltd.':
gt+=1
Above worked.
Considering there are more than 20 if statments and it takes a long period time to finish checking,I used dictionary as below
ipl=gs=gt=0
for file in glob.glob('*.xlsm'):
wb=load_workbook(file,data_only=True)
ws=wb["Tim"]
client=ws['B2'].value
companypool = {'Injection Parts Ltd.':ipl,
'Gulf Sample Ltd':gs,
'Great test Ltd.':gt}
if client in companypool:
print(companypool[client])
print(client)
companypool[client]+=1
The result is that companypool[client] always being 0 and failed to count.
Any codes wrong?
I am newbie to Python,thank you in advance.