以下はConfigParserによって解析されたファイルである:ここでofficial Python wiki for ConfigParser examplesで説明したようにのPython 2.xでのConfigParser複数行の値に空白行を剥離
[Ticket]
description = This is a multiline string.
1
2
4
5
7
ヘルパー関数は、次のとおり
def ConfigSectionMap(section):
dict1 = {}
options = Config.options(section)
for option in options:
try:
dict1[option] = Config.get(section, option)
if dict1[option] == -1:
DebugPrint("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1
得られた値である。
>>> print ConfigSectionMap('Ticket')['description']
This is a multiline string.
1
2
4
5
7
期待値であった:
>>> print ConfigSectionMap('Ticket')['description']
This is a multiline string.
1
2
4
5
7
これを修正するにはどうすればよいですか?
おかげで、しかし、あなたはすでに実現として、私は、Python 2.7を使用しています。残念ながら、Python 2.7用のConfigParserに_empty_lines_in_values_はありません。 – paragbaxi
@ ghee22:標準ライブラリに限定されていないなら、私が与えたSOのリンクで述べたようにConfigObjを使うことができます。 3重引用符を使用して値を囲むことができます。ここにはドキュメントがあります:http://www.voidspace.org.uk/python/configobj.html#the-config-file-format – jwd