接口开发
先安装一个模块:pip install flask 用它来启动一个服务,flask是一个web框架
1、知道接口是怎么开发的
2、避免别人操作你的数据库
3、mock服务(模拟一个服务)
一个简单的接口:
1 import flask 2 server = flask.Flask(__name__)#把当前这个python文件当做一个服务 3 @server.route('/login',methods=['get','post'])#装饰器 4 def zjr(): 5 return '登录成功!' 6 server.run(port=8989,debug=True)#启动服务,端口号为8989,修改后自动重启
启动后:
重新运行只能启动一个,否则端口号会重复,点击服务网址,加域名(http://127.0.0.1:8989/login)
访问服务:http://127.0.0.1:8989/login
操作excel
1.读excel
1 import xlrd#只能读 2 book = xlrd.open_workbook('zjr.xls') 3 print(book.nsheets)#excel里一共有多少sheet页 4 sheet = book.sheet_by_index(0)#sheet页的索引 5 # book.sheet_by_name('sheet1')#sheet页的名字 6 print(sheet.cell(0,0).value)#不加.value会显示数据的类型 7 print(sheet.cell(1,0))#显示第二行第一列的数据,不加.value会显示数据的类型 8 print(sheet.row_values(0))#显示某一行的数据 9 print(sheet.row_values(1)) 10 print(sheet.nrows)#这个Excel里总共有多少行 11 print(sheet.col_values(0))#某一列的数据 12 print(sheet.col_values(1)) 13 print(sheet.ncols)#总共有多少列
2.修改excel
1 import xlrd 2 from xlutils import copy#修改需要两个模块xlrd和xlutils 3 book1 = xlrd.open_workbook('zjr.xls')#打开原来的excel 4 new_book = copy.copy(book1)#拷贝一个新的excel 5 sheet = new_book.get_sheet(0)#获取一个sheet页 6 print(dir(sheet))#查看sheet有什么方法 7 sheet.write(1,3,'88')#第二行的第四列 8 sheet.write(1,1,'周继蓉') 9 new_book.save('zjr.xls') 10 #一定先关掉zjr.xls文件