python - 如何打印从今天起接下来的 3 个日期?
问题描述
我有一个代码可以告诉输入位置的天气。我想选择打印未来 3 天的天气,我需要向我的函数发送 3 个日期(带循环),每次不同的日期,如何从当天发送接下来 3 天的日期?
#This is my function
def weather(city, date):
#This is the part where I send it from the main to the function:
city = 'Paris'
while(i < 4):
i += 1
weather(city.lower(), dd/mm/yyyy)# Here instead of "dd/mm/yyyy" I need to send every time the next date from today.
解决方案
生成日期范围的最简单方法是使用pandas.date_range
as
import pandas as pd
dates = pd.date_range('2019-04-10', periods=3, freq='D')
for day in dates:
weather(city, day)
或者你可以坚持在接下来的几天循环,你可以使用datetime.timedelta
from datetime import date, timedelta
one_day_delta = timedelta(1)
day = datetime.date(2019, 4, 19)
for i in range(3)
day += one_day_delta
weather(city, day)
推荐阅读
- cuda - cudamemcpyasync,memcpy 在直接复制工作时无法在内核内部复制
- python - 有没有办法通过 Python 在 PowerPoint 幻灯片中的表格中添加一列?
- c# - 为什么 Dart 将进程参数包装在 C# 没有的引号中?
- c - Does the following violates strict aliasing
- python - 等待上一个函数在Python中完成
- java - 如何在双向多对多映射中添加数据?(这不是添加数据的正常过程)
- javascript - jszip中的压缩文件比未压缩的内容大
- firefox-headless - Firefox 的无头屏幕截图不起作用
- node.js - GraphQL 查询结果中未返回的扩展
- php - 如何在 php 中集成 Paytm 以接受付款