How to convert CRLF to LF on a Windows machine in Python

前端 未结 4 923
我寻月下人不归
我寻月下人不归 2020-12-14 20:20

So I got those template, they are all ending in LF and I can fill some terms inside with format and still get LF files by opening with "wb"

Those templates

4条回答
  •  隐瞒了意图╮
    2020-12-14 21:08

    It is possible to fix existing templates with messed-up ending with this code:

    with open('file.tpl') as template:
       lines = [line.replace('\r\n', '\n') for line in template]
    with open('file.tpl', 'w') as template:
       template.writelines(lines)
    

提交回复
热议问题