Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 作为日期对象的月份天数_Python_Date - Fatal编程技术网

Python 作为日期对象的月份天数

Python 作为日期对象的月份天数,python,date,Python,Date,如何为特定月份和年份中的每一天生成日期对象的列表 我尝试过使用日历模块,但这不是我想要的。使用timedelta模块,您可以很好地循环所有可能的值,并在月份发生变化时停止 from datetime import date, timedelta def generate_month_days(year, month): start_date = date(year, month, 01) cur_date = start_date while cur_date.mon

如何为特定月份和年份中的每一天生成
日期
对象的
列表


我尝试过使用
日历
模块,但这不是我想要的。

使用timedelta模块,您可以很好地循环所有可能的值,并在月份发生变化时停止

from datetime import date, timedelta

def generate_month_days(year, month):
    start_date = date(year, month, 01)

    cur_date = start_date
    while cur_date.month == start_date.month:
        yield cur_date
        cur_date += timedelta(days=1)

for d in generate_month_days(2015,11):
    print d