python - 为什么变量可以添加到'.json'和'.text'
问题描述
import requests
req=requests.get(json_url)
with open('xxx','w') as f:
f.write(req.text)
file_requests=req.json()
requests是一个模块,get是一个函数,所以req=requests.get(),但是req.txt和req.json()是什么,它也是一个函数吗?
解决方案
这一行:
requests.get(json_url)
返回 python 对象(http://docs.python-requests.org/en/master/api/#requests.Response)
requests.Response
:
- 有方法
json
(以 json 形式返回 http-body) - 有属性(文本和内容)
推荐阅读
- javascript - 警告:函数作为 React 子级无效。反应JS
- c# - 如何从泛型接口获取派生的原始类型?
- javascript - JavaScript:同时多次发布到页面
- matlab - 使用过滤器对象和 b,a 系数的结果非常不同
- flutter - 底部导航栏全白,如何修复?
- python - XML 到 Excel 中的表格形式
- android - 溢出菜单未出现在应用栏中
- r - ggpmisc::stat_poly_eq 中 output.type="numeric" 的每个方面的系数
- flutter - 使用 BuildContext 扑动 onGenerateRoute
- python - 在 Mac 上安装 scikit-learn