2015-09-08 44 views
-1
for wk in sorted(out.keys()): 
rec_date = datetime.datetime(*xlrd.xldate_as_tuple(wk, inputfp.datemode)).isocalendar()[1]#search for dates of current week 
if rec_date == datetime.date.today().isocalendar()[1]:#conditions to check current week dates 
    print '\nCurrent Week Number::' ,rec_date #printing the current week number 
    print 'Total Effort::',str(out[wk]) #total efforts of current week date 

下面是代碼,按照目前的週日期的加入細節,但我不需要根據這一週的日期本週的所有時間總和如何獲取本週的總詳情?

輸出我得到:

當前週數: :37 總工作量:: 29

當前週數:: 37 總工作量:: 18

當前週數:: 37 ŧ otal努力:: 20

我應該得到這樣本週和總工作量輸出:

當前週數:: 37 總工作量:: 67

回答

0

由週數收集所有的彙總一個字典,然後在循環結束時打印結果。

這樣,你正在積累的數字:

from collections import defaultdict 

results_by_week = defaultdict(int) 

for wk in sorted(out.keys()): 
    rec_date = datetime.datetime(*xlrd.xldate_as_tuple(wk, 
       inputfp.datemode)).isocalendar()[1] 
    if rec_date == datetime.date.today().isocalendar()[1]: 
     results_by_week[rec_date] += int(out[wk]) 

for weeknum, total in results_by_week.items(): 
    print('Week Number: {} Total Effort: {}'.format(weeknum, total))