0
我已經寫代碼來生成所有特定月份的日期排列的列表:如何字符串轉換成
nb_days = monthrange(2016, 2)[1]
dateDict = [datetime.date(year, month, day) for day in range(1, nb_days+1)]
outputItems = []
for dd in dateDict:
outputItems.append(dd.strftime('%Y-%m-%d'))
我的輸出是這樣的:
['2016-02-01', '2016-02-02', '2016-02-03', '2016-02-04', '2016-02-05', '2016-02-06', '2016-02-07', '2016-02-08', '2016-02-09', '2016-02-10', '2016-02-11', '2016-02-12', '2016-02-13', '2016-02-14', '2016-02-15', '2016-02-16', '2016-02-17', '2016-02-18', '2016-02-19', '2016-02-20', '2016-02-21', '2016-02-22', '2016-02-23', '2016-02-24', '2016-02-25', '2016-02-26', '2016-02-27', '2016-02-28', '2016-02-29']
我需要得到結果是這樣的:
[('2016-02-01', '0', '0', '0'), ('2016-02-02', '0', '0', '0'), ('2016-02-03', '0', '0', '0'), ('2016-02-04', '0', '0', '0'), .....]
你可以試試像這樣''outputItems.append(((dd.strftime('%Y-%m-%d'),)),)' 我不明白'0'在'('2016-02-01','0','0','0')'它取決於你如何添加它們。 –
'0'它只是一個值。謝謝你幫助我! – nas