当前位置:网站首页>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 :kpicode2、 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 !
边栏推荐
- LeetCode 300. Daily question of the longest increasing subsequence
- 99% 用户在 Power BI 云端报表常犯错误
- LeetCode 1626. The best team without contradiction
- 自定义View必备知识,Android研发岗必问30+道高级面试题
- QT 图片背景色像素处理法
- Sator launched Web3 game "satorspace" and launched hoobi
- 一文读懂数仓中的pg_stat
- Pychart ide Download
- ORACLE进阶(六)ORACLE expdp/impdp详解
- LeetCode 152. Product maximum subarray daily question
猜你喜欢

Seaborn data visualization

The latest interview experience of Android manufacturers in 2022, Android view+handler+binder

Sort out several important Android knowledge and advanced Android development interview questions

Temperature sensor chip used in temperature detector
ByteDance Android gold, silver and four analysis, Android interview question app
![[designmode] facade patterns](/img/79/cde2c18e2ec8b08697662ac352ff90.png)
[designmode] facade patterns

字节跳动Android面试,知识点总结+面试题解析

Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching

skimage学习(1)

DNS 系列(一):为什么更新了 DNS 记录不生效?
随机推荐
掌握这个提升路径,面试资料分享
最新Android高级面试题汇总,Android面试题及答案
智慧物流平台:让海外仓更聪明
射线与OBB相交检测
LocalStorage和SessionStorage
Sator a lancé le jeu web 3 "satorspace" et a lancé huobi
LeetCode 1774. The dessert cost closest to the target price is one question per day
邮件服务器被列入黑名单,如何快速解封?
Lowcode: four ways to help transportation companies enhance supply chain management
AI来搞财富分配比人更公平?来自DeepMind的多人博弈游戏研究
The latest interview experience of Android manufacturers in 2022, Android view+handler+binder
应用在温度检测仪中的温度传感芯片
第九届 蓝桥杯 决赛 交换次数
Flask搭建api服务
Test case management tool recommendation
ByteDance Android gold, silver and four analysis, Android interview question app
Master this set of refined Android advanced interview questions analysis, oppoandroid interview questions
Sator推出Web3游戏“Satorspace” ,并上线Huobi
值得一看,面试考点与面试技巧
谈谈 SAP 系统的权限管控和事务记录功能的实现