3

我有一个简单的例子:

test = """test
dsdssd
dsdssd
"""

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

print html_doc({ })

如何在每个字符串的末尾添加“回车”(\r)?

4

1 回答 1

12
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.

于 2012-08-09T15:58:59.207 回答