これを正しく理解しているかどうかはわかりませんが、構成ファイルを作成して、示したようなリストを簡単に読みたい場合は、configs.ini にセクションを作成します。
[section]
key = value
key2 = value2
key3 = value3
その後
>> config = ConfigParser.RawConfigParser()
>> config.read('configs.ini')
>> items = config.items('section')
>> items
[('key', 'value'), ('key2', 'value2'), ('key3', 'value3')]
これは基本的にあなたが必要だと言うものです。
一方、あなたが言っているのは、構成ファイルに次のものが含まれているということです。
[section]
couples = [("somekey1", "somevalue1"), ("somekey2", "somevalue2"), ("somekey3", "somevalue3")]
できることは、たとえば次のように構成パーサーを拡張することです。
class MyConfigParser(ConfigParser.RawConfigParser):
def get_list_of_tups(self, section, option):
value = self.get(section, option)
import re
couples = re.finditer('\("([a-z0-9]*)", "([a-z0-9]*)"\)', value)
return [(c.group(1), c.group(2)) for c in couples]
そして、新しいパーサーがリストを取得できます。
>> my_config = MyConfigParser()
>> my_config.read('example.cfg')
>> couples = my_config.get_list_of_tups('section', 'couples')
>> couples
[('somekey1', 'somevalue1'), ('somekey2', 'somevalue2'), ('somekey3', 'somevalue3')]
2番目の状況は、自分にとって物事を難しくしているだけだと思います.