编辑代码以在特定月份和年份停止下载
edit code to stop downloading on a certain month AND year
我目前正在使用以下代码下载一些数据。该代码运行良好,除非我想在一年中的某个月份停止下载。
例如如果我想在 month=02 和 year=2019 停止下载,那是行不通的。我将最大月份设置为 02,将最大年份设置为 2019,但是它只下载每年的第二个月,而不是最多下载 2019 年的第二个月(前几年的每隔一个月)
如何编辑我的代码来解决这个问题?
存在多个问题。首先,更改行
while month <= max_month and year <= max_year:
到
while month < max_month or year < max_year:
因为您希望循环在任一条件为真时继续。然后,更改行
if month == max_month:
到
if month == 12:
您还应该删除尾随的 0
s(例如 month = 01
),因为它们在 Python 2 中将被视为八进制(并在 Python 3).
我目前正在使用以下代码下载一些数据。该代码运行良好,除非我想在一年中的某个月份停止下载。
例如如果我想在 month=02 和 year=2019 停止下载,那是行不通的。我将最大月份设置为 02,将最大年份设置为 2019,但是它只下载每年的第二个月,而不是最多下载 2019 年的第二个月(前几年的每隔一个月)
如何编辑我的代码来解决这个问题?
存在多个问题。首先,更改行
while month <= max_month and year <= max_year:
到
while month < max_month or year < max_year:
因为您希望循环在任一条件为真时继续。然后,更改行
if month == max_month:
到
if month == 12:
您还应该删除尾随的 0
s(例如 month = 01
),因为它们在 Python 2 中将被视为八进制(并在 Python 3).