python 读取配置文件

Python读取配置文件并打印文件信息


配置文件field_len.conf内容为:

[ddl_max_len]
NUMBER_MAX_LEN=10
VARCHAR2_MAX_LEN=1024

[dml_max_len]
NUMBER_MAX_LEN=10
VARCHAR2_MAX_LEN=1024
BLOB_MAX_LEN=500M
FLOAT_MAX_LEN = P20S8
DATE = 12
TIMESTAMP(6) = 12


import ConfigParser

def db_get_args_cfginfo(db_field_len_file):
    db_config = ConfigParser.ConfigParser()
    db_config.read(db_field_len_file)

    return db_config

db_field_len_file = "C:/i2test/field_len.conf"
db_config = db_get_args_cfginfo(db_field_len_file)

dcs =  db_config.sections()
print dcs

for config_data_type in db_config.options(dcs[0]):
    print "-----------------------------"
    print config_data_type
    print config_data_type.upper()

for config_data_type in db_config.options(dcs[1]):
    print "=============================="
    print config_data_type
    print config_data_type.upper()

执行程序结果:

['ddl_max_len', 'dml_max_len']
-----------------------------
number_max_len
NUMBER_MAX_LEN
-----------------------------
varchar2_max_len
VARCHAR2_MAX_LEN
==============================
number_max_len
NUMBER_MAX_LEN
==============================
varchar2_max_len
VARCHAR2_MAX_LEN
==============================
blob_max_len
BLOB_MAX_LEN
==============================
float_max_len
FLOAT_MAX_LEN
==============================
date
DATE
==============================
timestamp(6)
TIMESTAMP(6)

你可能感兴趣的:(python,编程语言,python)