内置模块:ConfigParser
ConfigParser 的作用:
读取格式化配置文件
ConfigParser 对配置文件有要求
1.必须要有 sections ,如:[mysql]
2.键值分隔必须为 = ,会忽略 = 两边的空格
3.除 = 号外的其它符号,也会被获取,引号也会被获取
示例
[mysql]
host = 127.0.0.1
user = root
password = passowrd
代码示例
base_odps.py
from odps import ODPS
from odps import options
from ConfigParser import ConfigParser
# set proxy
# options.api_proxy = {'http': '127.0.0.1:10000'}
# options.data_proxy = {'http': '127.0.0.1:10000'}
# set sql script support
options.sql.settings = {
"odps.sql.submit.mode": "script"}
class Properties(object):
"""get odps config"""
def __init__

本文介绍了Python2.7中ConfigParser模块的作用,它用于读取格式化的配置文件。ConfigParser要求配置文件包含sections,键值对之间用等号分隔,并且会保留等号两侧的空格以及引号。
最低0.47元/天 解锁文章
4万+





