将webquery中的json内容保存到python中的文件

将webquery中的json内容保存到python中的文件,python,json,Python,Json,url为我提供了json输出,但我想将该输出保存到python中的json文件中 这是密码 import urllib2 import json url = "http://query.yahooapis.com/v1/public/yql?q=select%20item.yweather:condition.code,item.yweather:condition.text,item.yweather:condition.temp%20from%20weather.forecast%20whe

url为我提供了json输出,但我想将该输出保存到python中的json文件中

这是密码

import urllib2
import json
url = "http://query.yahooapis.com/v1/public/yql?q=select%20item.yweather:condition.code,item.yweather:condition.text,item.yweather:condition.temp%20from%20weather.forecast%20where%20woeid%3D2295420&format=json"
data = urllib2.urlopen(url)
print data
我得到的结果是

  <<addinfourl at 159473132 whose fp = <socket._fileobject object at 0x981436c>>
我想要json输出,而不是这个套接字地址……

返回类似文件的对象。要获取内容,请使用它的读取方法

f = urllib2.urlopen(url)
try:
    print f.read()
finally:
    f.close()
urllib.urlopen不返回页面中的实际数据,而是返回响应。你可能想打电话。请阅读该对象