python - 如何返回星期几,然后从 Weather API 返回星期的名称?
问题描述
def getForecast():
zip2 = '60103'
url = 'http://api.openweathermap.org/data/2.5/forecast?zip=' \
'' + zip2 +
',us&appid=7f5941b864a5fde449419c6aaca23540&units=imperial'.format(zip2)
response = requests.get(url)
data2 = response.json()
date_list = (data2['list'][0]['dt_txt'])
date_list = date_list.split()
del date_list[-1]
new = list(date_list[0].split('-'))
new1 = [int(x) for x in new]
print(calendar.weekday(new1))
根据日历文档,“new1”应该以正确的格式返回星期几,但我收到一个错误:“ weekday() missing 2 required positional arguments: 'month' and 'day'
”当我手动插入年、月、日时,我收到的星期几只是美好的。
解决方案
docs,您需要提供 3 个参数year, month, day
才能weekday
运行,但是您给了 a list
,您new1
的类型list
是这样 的
import calendar
# if you have a list with year, month, day
# for example this
new1 = [2018, 6, 19]
print(calendar.weekday(*new1)) # important to put * before new1
# output
# 1
推荐阅读
- node.js - events.js:288 抛出错误;// 未处理的“错误”事件
- c# - C#6 字符串插值 + 短格式字符串错误?
- web-applications - Bokeh Webapp 开发:实时代码更新?
- python - python单元测试补丁模拟方法不返回返回值
- node.js - 在 App Engine 中删除我的应用程序域中的“appspot”
- accessibility - 我们可以使用 mxgraph 创建可访问的图表吗?
- mysql - Redshift SQL,连接刺痛和年份
- azure - Azure 流量管理器 - 多个订阅密钥
- r - 从 R 中的另一个数据框创建多个数据框
- android - Android:如何将媒体播放器作为服务托管?