`

python中使用配置文件

 
阅读更多

1. python中使用配置文件

 

配置文件 stats_ui.conf

 

[country]
1001=230,104,48,76,56
1002=4,5,14,18,27,32,37,38,49,50,51,59,60,77,90,96,98,111,123,127,156,164,172,230,234,235,236
1003=1,12,17,20,22,36,43,55,56,58,67,69,74,76,83,88,97,99,101,108,109,128,132,133,134,137,138,139,143,152,165,166,178,183,188,189,190,196,199,201,203,222,227,233
1004=2,3,7,16,19,23,28,33,48,63,78,94,100,102,104,106,107,112,113,115,116,120,121,122,124,125,126,129,145,146,147,154,157,167,171,176,177,182,186,192,197,209,215,216,218,219,225,232,238,242
1005=10,29,31,46,62,79,93,173,185,231
1006=8,21,24,25,35,40,41,42,44,47,52,54,57,61,64,66,68,75,81,84,85,87,114,130,131,135,136,141,144,150,153,155,158,159,161,163,187,191,194,195,202,204,205,206,210,212,214,220,226,228,244,245,246
1007=13,45,70,72,91,117,170,175,184,193,239,241

[model]
2001=118,2,20,11,9

[nqver]
3001=70,69,77
3002=9,61,63,55,86,59,58,57,54,53,65,64,71,68,80,76,78,67,66,85,88,82,81,87,84,89,90
3003=21,8,5,4,2,62,60,83,74,79,7,6,11
3004=

[os]
4001=15
4002=11,4,5,9,14
4003=2,6,16,3
4004=10,1,12,13,2,6,16
4005=

[oslang]
5001=

[subcoop]
6001=
 

  python引入使用

 

import os
import ConfigParser
abspath = os.path.dirname(os.path.abspath(__file__))
CONFIG = abspath + '/../conf/stats_ui.conf'
cf = ConfigParser.ConfigParser()
cf.read(CONFIG)
 

  python代码中使用

 

#dim=country/model/os/oslang/nqver/...
#category=1001/....
subdims = cf.get(dim,category)
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics