当前位置:网站首页>Flask搭建api服务-SQL配置文件
Flask搭建api服务-SQL配置文件
2022-07-07 15:34:00 【python与大数据分析】
续前文(Flask搭建api服务)把SQL语句以字典的方式存储起来,配置和代码没有分割开来,一直纠结如何处理配置文件中多行配置项的问题,查了半天,其实这个问题不存在的,只要在配置项中跨行部分前面追加一个空格即可。
ini是传统的主流配置文件。
ini支持的数据类型有限,将所有的值都默认成字符串(字符串最外面不需要添加引号)。
ini配置文件必须使用[](section)进行分组,每一个键称为option。
1、追加配置文件SQL.ini
[KPIDB]
sql1 = select a.*
from kpi_value a
where a.kpicode in ('01010101','02010101','03010101')
and a.datelevel='01'
and a.regionlevel='02'
sql2 = select a.*
from kpi_value a
where a.kpicode in ('01010101','02010101','03010101')
and a.datelevel='01'
and a.regionlevel='02'
and a.datecode>=:begindate and a.datecode<=:enddate
sql3 = select a.*
from kpi_value a
and a.datelevel='01'
and a.regionlevel='02'
and a.datecode>=:begindate and a.datecode<=:enddate
and a.kpicode in :kpicode2、在app.py中追加一个configparser读取
import configparser
config = configparser.ConfigParser()
config.read('SQL.ini',encoding="utf-8-sig")
DBSECTION='KPIDB'3、在各个路由函数中使用config项替代原来的字典方式
# sqltext = sqldict[sqlid]
sqltext = config[DBSECTION][sqlid]pycharm读取ini配置文件,使用自带的configparser模块。
具体步骤如下:
1、导入ConfigParser类;
2、实例化ConfigParser;
3、使用read()方法打开并读取文件内容;
4、使用get()方法,根据section和option获取指定的值。
最后,谢谢关注,谢谢支持!
边栏推荐
- null == undefined
- Ray and OBB intersection detection
- Lowcode: four ways to help transportation companies enhance supply chain management
- Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching
- LeetCode 312. Poke balloon daily
- 谈谈 SAP 系统的权限管控和事务记录功能的实现
- 谎牛计数(春季每日一题 53)
- skimage学习(2)——RGB转灰度、RGB 转 HSV、直方图匹配
- [medical segmentation] attention Unet
- Master this set of refined Android advanced interview questions analysis, oppoandroid interview questions
猜你喜欢

Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images
最新高频Android面试题目分享,带你一起探究Android事件分发机制

QML初学

Skimage learning (3) -- adapt the gray filter to RGB images, separate colors by immunohistochemical staining, and filter the maximum value of the region

skimage学习(1)

QT picture background color pixel processing method

Lowcode: four ways to help transportation companies enhance supply chain management

科普达人丨一文弄懂什么是云计算?
![[medical segmentation] attention Unet](/img/f4/cf5b8fe543a19a5554897a09b26e68.png)
[medical segmentation] attention Unet

最新Android面试合集,android视频提取音频
随机推荐
skimage学习(1)
Module VI
Skimage learning (3) -- adapt the gray filter to RGB images, separate colors by immunohistochemical staining, and filter the maximum value of the region
LeetCode 1043. 分隔数组以得到最大和 每日一题
爬虫(17) - 面试(2) | 爬虫面试题库
LeetCode 300. Daily question of the longest increasing subsequence
LeetCode 1981. 最小化目标值与所选元素的差 每日一题
LeetCode 213. 打家劫舍 II 每日一题
LeetCode 1031. 两个非重叠子数组的最大和 每日一题
Process from creation to encapsulation of custom controls in QT to toolbar (I): creation of custom controls
电脑无法加域,ping域名显示为公网IP,这是什么问题?怎么解决?
Skimage learning (1)
LeetCode 1477. Find two subarrays with sum as the target value and no overlap
低代码(lowcode)帮助运输公司增强供应链管理的4种方式
Interface oriented programming
【Seaborn】组合图表、多子图的实现
模块六
Read PG in data warehouse in one article_ stat
最新2022年Android大厂面试经验,安卓View+Handler+Binder
Flask搭建api服务-生成API文档