比如:
application.mode=dev
比如:
application.mode=dev
|
1
配置文件最好选一种标准化的格式,比如 ini, json, yaml, 再用标准化的方式去读取(而非自己去按行读,按等号分割),这样就优雅了吧。
|
|
fyMay 19, 2016
2
dict([x[:-1].split('=') for x in f.readlines()])
|
|
tongleMay 19, 2016
3
ConfigParser 也许你需要这个
|
|
imn1May 19, 2016
4
configparser — Configuration file parser
This module provides the ConfigParser class which implements a basic configuration language which provides a structure similar to what ’ s found in Microsoft Windows INI files. You can use this to write Python programs which can be customized by end users easily. |
|
haozhangMay 19, 2016 via iPhone
5
hocon
|
|
yongzhongMay 19, 2016
8
ConfigParser +1
|
|
ayaseangleMay 20, 2016 via Android
10
这像是 Java 的 properties 文件。。。。
|
|
hrongMay 20, 2016 via Android
11
java 有 getBundle(),连 bash 都有 source,为毛 Python 就木有原生?不可能啊。。。我不懂 Python ,你们别拍我
|
|
ryanking8215May 20, 2016
12
@hrong 是不可能啊。 import 模块或文件不就行啦?!
|
|
bramblexMay 20, 2016
13
一行代码就解决的问题楼上一群人非要引进来一个库,用不用顺便再 require 一个 leftpad ?
|
|
araralorenMay 20, 2016
14
...同意楼上说的,一句话就能解决的事情,为啥要引入库。。
|
|
linuxchildMay 20, 2016
15
2L 的已经很 pythonic 了
|
|
RadishWindMay 21, 2016
16
直接把配置文件写成 dict 的格式, import
|
|
lianghuiMay 23, 2016
17
|