擅长:python、mysql、java
<p>为了使用我的示例,您的文件“abc.txt”需要如下所示:</p>
<pre><code>[your-config]
path1 = "D:\test1\first"
path2 = "D:\test2\second"
path3 = "D:\test2\third"
</code></pre>
<p>然后在您的软件中,您可以使用配置分析器:</p>
<pre><code>import ConfigParser
</code></pre>
<p>然后在你的代码中:</p>
<pre><code> configParser = ConfigParser.RawConfigParser()
configFilePath = r'c:\abc.txt'
configParser.read(configFilePath)
</code></pre>
<p>用例:</p>
<pre><code>self.path = configParser.get('your-config', 'path1')
</code></pre>
<p><strong>*编辑(@human.js)</strong></p>
<p>在python 3中,ConfigParser被重命名为ConfigParser(<a href="https://stackoverflow.com/questions/14087598/python-3-importerror-no-module-named-configparser">as described here</a>)</p>