- 论坛徽章:
- 0
|
import ConfigParser
class varDB:
pass
myconfig = ConfigParser.ConfigParser()
myconfig.read('mailset.ini')
newvarDB = varDB()
for section in myconfig.sections():
for option in myconfig.options(section):
newvarDB.__dict__[section+'_'+option] = myconfig.get(section, option)
for key in newvarDB.__dict__.keys():
print key, newvarDB.__dict__[key]
现在你要的变量都在newvarDB里面了
以下是测试文件内容:
[MailInfo]
path = G:\mail
delete = no
[UserInfo]
smtpauth = xxandxx@163.com
pop3user = xxandxx
smtpuser = xxandxx
[ServerInfo]
smtpserver = smtp.163.com
pop3server = pop3.163.com
小名 = 中国
大名 = 提阿姆
测试结果:
UserInfo_smtpuser xxandxx
ServerInfo_pop3server pop3.163.com
MailInfo_delete no
UserInfo_pop3user xxandxx
ServerInfo_smtpserver smtp.163.com
ServerInfo_大名 提阿姆
ServerInfo_小名 中国
UserInfo_smtpauth xxandxx@163.com
MailInfo_path G:\mail
以上的变量要用的话如下:
newvarDB.MailInfo_path
newvarDB.ServerInfo_小名
.etc |
|