码迷,mamicode.com
首页 > 其他好文 > 详细

record-11 网络编程 打开文件

时间:2018-01-18 22:09:08      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:highlight   load   notice   参数   close   com   名称   line   soj   

#open()
#urlopen()
#方法名称不同
#参数不同
#只能以只读模式打开网络资源文件

from urllib.request import urlopen
from urllib.parse import quote
from json import loads
from time import time,sleep

print(‘请输入要查询的城市名称:‘)
s=input()
s1=quote(s)
#print(s1)


url=‘http://www.sojson.com/open/api/weather/json.shtml?city=‘+s1
f=urlopen(url)
#read()
#readline()
#readlines()
result=f.read().decode()
result=loads(result) #a=a+1

day1=result[‘data‘][‘forecast‘][0]
print(‘日期:‘,day1[‘date‘])
print(‘天气状态:‘,day1[‘type‘])
print(‘风向:‘,day1[‘fx‘])
print(‘今天最低温度:‘,day1[‘low‘])
print(‘今天最高温度:‘,day1[‘high‘])
print(‘注意事项:‘,day1[‘notice‘])


f.close()

  

record-11 网络编程 打开文件

标签:highlight   load   notice   参数   close   com   名称   line   soj   

原文地址:https://www.cnblogs.com/minkillmax/p/8313133.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!