-1

例如,我有一个名为 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?谢谢!

4

1 回答 1

1

我把我的解决方案放在这里:

https://github.com/hanfeisun/meta_model

采用

python  test.py

看结果

于 2012-11-09T07:13:04.090 回答