简体   繁体   中英

How can I get new line with configparser file key values?

python code

import configparser
cfg = configparser.ConfigParser()
cfg.read('config.ini')
message = cfg['common']['msg']
print(message)

config.ini

[common]
msg = hi /n how are you?

output

hi /n how are you?

But I need newline instead of /n printitng

hi
how are you?

ConfigParser escapes '\n' in ini values as '\n', so try replacing it.

message = cfg['common']['msg']
message.replace('\\n', '\n')
print(message)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM