The testing code:
import ConfigParser
config = ConfigParser.ConfigParser()
config.read('test_config.ini')
orig_str = """line1\r\nline2"""
config_str = config.get('General', 'orig_str')
print orig_str == config_str
and the content of test_config.ini is:
[General]
orig_str = line1\r\nline2
What I want is the config_str can be the same value as the orig_str.
Any help would be appreciated!
If you want to write multiline configuration values, you just need to prepend a space at the beginning of the following lines. For example:
returns
'line1\nline2'in my OS (Linux), but maybe in a different OS might return the'\r'as well. Otherwise, it would be easy to replace'\n'with'\r\n'as you need.I’d say that whatever library you’re using to encode the message should take care of the replacement. Anyway, if that’s not the case, you can create your own
ConfigParseras follows: