例如,我有一个名为 rule1.conf 的配置文件,如下所示:
[Basis]
user = "sunhf"
time = "2012-12-31"
[Bowtie]
path = "/usr/bin/bowtie"
index = "/mnt/Storage/sync/hg19"
和这样的models.py(使用名为magic.py
..的包):
from magic import Section
class Conf:
__confname__ = None
basis = Section(["user", "time"])
bowtie = Section(["path", "index"])
最后,像这样的 viewer.py :
from models import Conf as my_conf
my_conf.__confname__ = "rule1.conf" // bind to the config file, I have no ideas how to do this
print my_conf.basis.user // output: `sunhf`
print my_conf.bowtie.index // output: `/mnt/Storage/sync/hg19`
当我viewer.py
在命令行中运行时:
$ python viewer.py
sunhf
/mnt/Storage/sync/hg19
有没有人对如何实施有任何想法magic.py
?谢谢!