当前位置:网站首页>Flask build API service SQL configuration file
Flask build API service SQL configuration file
2022-07-07 17:08:00 【Python and big data analysis】
Continued (Flask build api service ) hold SQL Statements are stored in a dictionary , Configuration and code are not separated , I have been struggling with the problem of how to deal with multi line configuration items in the configuration file , For a long time , In fact, this problem does not exist , Just add a space in front of the cross line part in the configuration item .
ini Is a traditional mainstream configuration file .
ini The supported data types are limited , Default all values to string ( There is no need to add quotation marks to the outside of the string ).
ini The configuration file must use [](section) Grouping , Each key is called option.
1、 Append configuration file 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 :kpicode
2、 stay app.py Add a configparser Read
import configparser
config = configparser.ConfigParser()
config.read('SQL.ini',encoding="utf-8-sig")
DBSECTION='KPIDB'
3、 Use in each routing function config Item replaces the original dictionary method
# sqltext = sqldict[sqlid]
sqltext = config[DBSECTION][sqlid]
pycharm Read ini The configuration file , Use native configparser modular .
The specific steps are as follows :
1、 Import ConfigParser class ;
2、 Instantiation ConfigParser;
3、 Use read() Method to open and read the contents of the file ;
4、 Use get() Method , according to section and option Gets the specified value .
Last , Thank you for your attention , Thank you for your support !
边栏推荐
- SlashData开发者工具榜首等你而定!!!
- Sqlserver2014+: create indexes while creating tables
- 【视频/音频数据处理】上海道宁为您带来Elecard下载、试用、教程
- Binary search tree (basic operation)
- Interface oriented programming
- 应用在温度检测仪中的温度传感芯片
- Sator推出Web3游戏“Satorspace” ,并上线Huobi
- typescript ts基础知识之tsconfig.json配置选项
- 【饭谈】Web3.0到来后,测试人员该何去何从?(十条预言和建议)
- 最新高频Android面试题目分享,带你一起探究Android事件分发机制
猜你喜欢
Binary search tree (basic operation)
LeetCode刷题day49
字节跳动Android面试,知识点总结+面试题解析
Shallow understanding Net core routing
Skimage learning (1)
SlashData开发者工具榜首等你而定!!!
Pisa-Proxy SQL 解析之 Lex & Yacc
skimage学习(3)——Gamma 和 log对比度调整、直方图均衡、为灰度图像着色
Sort out several important Android knowledge and advanced Android development interview questions
time标准库
随机推荐
最新Android面试合集,android视频提取音频
最新2022年Android大厂面试经验,安卓View+Handler+Binder
ORACLE进阶(六)ORACLE expdp/impdp详解
测试用例管理工具推荐
[medical segmentation] attention Unet
Ray and OBB intersection detection
字节跳动Android面试,知识点总结+面试题解析
掌握这个提升路径,面试资料分享
skimage学习(3)——使灰度滤镜适应 RGB 图像、免疫组化染色分离颜色、过滤区域最大值
LeetCode 1986. 完成任务的最少工作时间段 每日一题
【饭谈】如何设计好一款测试平台?
低代码(lowcode)帮助运输公司增强供应链管理的4种方式
【视频/音频数据处理】上海道宁为您带来Elecard下载、试用、教程
Flask搭建api服务-生成API文档
ATM system
Pisa-Proxy SQL 解析之 Lex & Yacc
Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching
LeetCode 1986. The minimum working time to complete the task is one question per day
服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
如何选择合适的自动化测试工具?