2

I have a config File "Email_Properties.cfg" as below

[email_Properties]
Subject=Security keywords Scan Info
Body=securityDetails\n Note : This is an auto generated mail

I am using ConfigParser to read file and print the content, Not able to get newLine using \n

config = ConfigParser.ConfigParser()
config.readfp(open(r'Email_Properties.cfg'))
body=config.get('email_Properties', 'Body')
print body

output:

securityDetails\n Note : This is an auto generated mail

How i can get NewLine present in the string of Config file ? Expected output as below,

securityDetails
Note : This is an auto generated mail

1 Answer 1

5

ConfigParser escapes \n in ini values as \\n, so try with something like

body.replace('\\n', '\n')

FWIW: The question's example is in Python 2, but for users of Python >=3.2: ConfigParser.read_file() replaces the ConfigParser.readfp() which as of then is deprecated. This is not affecting the question/solution though.

Sign up to request clarification or add additional context in comments.

1 Comment

You're welcome. Please accept answer if this solved your problem :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.