Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add carriage return in python?

Tags:

python

jinja2

I have a simpl example:

test = """test
dsdssd
dsdssd
"""

def html_doc(args):
    return Environment().from_string(test).render(args)

print html_doc({ })

How to add "carriage return" (\r) in the end of each string ?

like image 689
Bdfy Avatar asked Jul 04 '26 07:07

Bdfy


1 Answers

test = str.replace(test, '\n', '\r\n')

EDIT: Python automatically tries to take care of newlines for reading and writing files, but I assume because the question is tagged as jinja2 that this string isn't being written to a file.

like image 181
Jordan Avatar answered Jul 05 '26 20:07

Jordan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!