Python:使用ConfigObj创建.py文件

时间:2012-03-24 22:41:47

标签: python config-spec configobj

我正在尝试使用ConfigObj创建一个python .py文件。

我面临的问题如下 -

  1. 如何使用configObj附加起始参数(classname,init语句),import语句等?
  2. 在ConfigObj中,我们可以使用节分隔符。如何将注释用作节名?显然,.py文件中的任何错误代码都不会运行。所以,我想使用注释作为章节标题来分隔。
  3. 以下是我正在尝试使用的configspec文件的代码 - (是的,我正在使用OpenFlow) -

    from mininet.topo import Topo, Node
    
    class MyTopo( Topo ):
        "Simple topology example."
    
        def __init__( self, enable_all = True ):
            "Create custom topo."
    
            # Add default members to class.
            super( MyTopo, self ).__init__()
    
    
            [["Define_Nodes"]]
            [[__many__]]
    
            [["Add_nodes"]]
        [[__many__]]
    
        [["Add_edges"]]
        [[__many__]]
    
        # Consider all switches and hosts 'on'
        self.enable_all()
    
    topos = { 'mytopo': ( lambda: MyTopo() ) }
    

    最后,当我运行此规范时,我的代码返回以下错误 -

    in _handle_configspec
    raise ConfigspecError('Parsing configspec failed: %s' % e)
    ConfigspecError: Parsing configspec failed: Invalid line at line "1".       
    

    显然,这意味着我无法使用ConfigObj创建正确的configspec类型。

    我的2点问题的任何答案都会很棒!

0 个答案:

没有答案