当前位置:网站首页>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 !
边栏推荐
- 【黄啊码】为什么我建议您选择go,而不选择php?
- LeetCode 1186. Delete once to get the sub array maximum and daily question
- LeetCode 1031. Maximum sum of two non overlapping subarrays
- The process of creating custom controls in QT to encapsulating them into toolbars (II): encapsulating custom controls into toolbars
- 射线与OBB相交检测
- 字节跳动Android金三银四解析,android面试题app
- 面向接口编程
- typescript ts基础知识之tsconfig.json配置选项
- os、sys、random标准库主要功能
- 服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
猜你喜欢
值得一看,面试考点与面试技巧
Sort out several important Android knowledge and advanced Android development interview questions
掌握这个提升路径,面试资料分享
[image sensor] correlated double sampling CDs
SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
最新Android高级面试题汇总,Android面试题及答案
skimage学习(2)——RGB转灰度、RGB 转 HSV、直方图匹配
NeRF:DeepFake的最终替代者?
正在准备面试,分享面经
测试用例管理工具推荐
随机推荐
mysql使用笔记一
ATM系统
[designmode] template method pattern
The process of creating custom controls in QT to encapsulating them into toolbars (II): encapsulating custom controls into toolbars
Direct dry goods, 100% praise
[PHP] PHP interface inheritance and interface multi inheritance principle and implementation method
Sator launched Web3 game "satorspace" and launched hoobi
掌握这个提升路径,面试资料分享
LeetCode 403. 青蛙过河 每日一题
一文读懂数仓中的pg_stat
Sator推出Web3游戏“Satorspace” ,并上线Huobi
电脑无法加域,ping域名显示为公网IP,这是什么问题?怎么解决?
LeetCode 1986. 完成任务的最少工作时间段 每日一题
Module VI
掌握这套精编Android高级面试题解析,oppoAndroid面试题
os、sys、random标准库主要功能
AI来搞财富分配比人更公平?来自DeepMind的多人博弈游戏研究
Pychart ide Download
99% 用户在 Power BI 云端报表常犯错误
Binary search tree (basic operation)