• python 读取配置文件ini ---ConfigParser


    Python读取ini文件需要用到 ConfigParser 模块

    关于ConfigParser模块的介绍详情请参照官网解释:https://docs.python.org/2.7/library/configparser.html

    • 要读取的ini文件(configfile.ini)如下:
    1. 以"[browserType ]"做section,browserName 为options
    [browserType]
    #browserName = Firefox
    browserName = Chrome
    #browserName = IE
    
    
    [account]
    user = test1
    #user = admin
    
    [language]
    language = EN
    #language = CN
    
    [country]
    country = US
    #country = FR
    #country = IT
    •  get(section,option) 得到section中option的值,返回为string类型
    • 在自动化测试框架中读取每个配置文件中的值,并返回以做调用或者拼接
    
    
    import ConfigParser

    class
    ReadConfigFile(object): def get_value(self): config = ConfigParser.ConfigParser() config.read("configfile.ini") browserName = config.get('browserType','browserName') account = config.get('accountType','user') language = config.get('languageType','language') country = config.get('countryType','country') return [browserName,account,language,country] trcf = ReadConfigFile() print '***********************************' print trcf.get_value() print '***********************************'

  • 相关阅读:
    linux 查看系统负载:uptime
    centos who命令 查看当前登录系统用户信息
    centos7 管理开机启动:systemd
    Linux ethtool 命令
    Linux ifconfig 命令
    linux centos7 目录
    POJ 1169
    POJ 1163
    POJ 1154
    POJ 1149
  • 原文地址:https://www.cnblogs.com/lanbing/p/9443812.html
Copyright © 2020-2023  润新知