Hi all,
I wanted to write the following line to the file.

sys.stdout.write("123: The metro polis\n")

But the line that was written is:

sys.stdout.write("100: The metro polis
")

How do I get the \n to be written in the text form to the? file(ie it should not be interpreted as a newline character, instead it should be printed as it is ie as "\n" only.

Any help would be greatly appreciated.

And I had extracted the "123: The metro polis" as a list item from some other string.
i concatenated the string and the list item as follows:
ll[1] --------> this is> 123: The metro polis
str = "sys.stdout.write"
Concatenation :
str += ll[1]

Is this what you are trying to do?

sys.stdout.write("123: The metro polis\\n")

And there is also form of raw string:

sys.stdout.write(r"123: The metro polis\n")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.