Python_configparser模块读取配置文件
config.ini
[phone] imei = 123456789 num = 0 / 14 build = 00WWYL
test.py
CUR_DIR = os.path.dirname(os.path.abspath(__file__)) configFilePath = os.path.join(CUR_DIR, '../bin/config.ini') def get_config_values(self, section, option): config = configparser.ConfigParser() # 避免乱码问题读取配置文件 config.read(configFilePath, encoding='utf-8') return config.get(section=section, option=option) IMEI = get_config_values('phone', 'imei') num = get_config_values('phone', 'num') build = get_config_values('phone', 'build')