python ConfigParser使用

来源:互联网 发布:强制视频软件多少钱 编辑:程序博客网 时间:2024/05/18 03:49

ConfigParser配置文件传递参数

使用方法:

  1. 创建一个配置文件,参数格式如下:
    [init]unit_time = 60max_time = 60memcache_threshold = 1ssd_threshold = 2mem_log_file_path = /usr/local/monitor/hotpoint/mem.logssd_log_file_path = /usr/local/monitor/hotpoint/ssd.logreal_time_log_file_path = /var/log/nginx/nginx_hot_access.log
    中括号是一个域,域下面是参数
  2. import ConfigParserconf = ConfigParser.ConfigParser()conf.read("/usr/local/monitor/hotpoint/hotUrl.conf")print "unit_time: %s" % (conf.get("init", "unit_time"))print "max_time: %s" % (conf.get("init", "max_time"))print "memcache_threshold: %s" % (conf.get("init", "memcache_threshold"))print "ssd_threshold: %s" % (conf.get("init", "ssd_threshold"))print "mem_log_file_path: %s" % (conf.get("init", "mem_log_file_path"))print "ssd_log_file_path: %s" % (conf.get("init", "ssd_log_file_path"))print "real_time_log_file_path: %s" % (conf.get("init", "real_time_log_file_path"))
    具体可以参照http://blog.chinaunix.net/uid-10597892-id-3535639.html

0 0
原创粉丝点击