record-11 网络编程 打开文件

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

包名就是一个文件夹,包含许多的模块
模块就是一个文件,文件里包含其他的函数之类的。详解:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014318447437605e90206e261744c08630a836851f5183000 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()

  

posted @ 2018-01-18 21:30  minkillmax  阅读(414)  评论(0编辑  收藏  举报